7

I am automating for the following page on CHROME Browser

https://study.yupl.us/studies/5d5a64aa8b5bb92fb776753b?auth=false

Here I'm able to identify the unique element from the console for the XPATH used

$x('//button[text()="START STUDY"]')

But when the same code is integrated with the script and run.

Integrated Script -

from selenium.webdriver import Chrome
driver = Chrome('/Users/downloads/chromedriver')
driver.get('https://study.yupl.us/studies/5d5a64aa8b5bb92fb776753b?auth=false')
driver.maximize_window()
sleep(8)
driver.find_element_by_xpath('//button[text()="START STUDY"]').click()

I get the following error

Traceback (most recent call last):
 File "/Users/PycharmProjects/Practice/t.py", line 54, in <module>
 driver.find_element_by_xpath('//button[text()="START STUDY"]').click()
 File "/Users/PycharmProjects/Study/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
 self._execute(Command.CLICK_ELEMENT)
 File "/Users/PycharmProjects/Study/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
 return self._parent.execute(command, params)
 File "/Users/PycharmProjects/Study/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
 self.error_handler.check_response(response)
 File "/Users/PycharmProjects/Study/venv/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
 raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button class="ui button" role="button" style="background-color: rgb(31, 186, 238); color: white; border-radius: 0px; padding-left: 40px; padding-right: 40px; font-family: &quot;Open Sans&quot;; font-size: 17px; font-weight: 600; line-height: 20px; text-align: center; width: 200px; height: 50px; margin-top: 26px;">...</button> is not clickable at point (1047, 320). Other element would receive the click: <div>...</div>
 (Session info: chrome=76.0.3809.132)

I have tried to click on the element using the ActionChains class as well. Even then the same issue is got

Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
asked Sep 5, 2019 at 14:28
1
  • 1
    Looks like the element that you wanted to perform a click on is obscured by another element. I believe you would have already verified the state of the element before the click; Things you can consider doing is perform a wait and may be maximize the window/scroll to the element which ever is applicable. Commented Sep 5, 2019 at 20:33

2 Answers 2

7

Try using JavaScriptExecutor

C#

IWebElement element = driver.FindElement(By.XPath("//button[@role='button']"));
IJavaScriptExecutor jse2 = (IJavaScriptExecutor)driver;
jse2.ExecuteScript("arguments[0].click()", element);

Python

element = driver.find_element_by_xpath("//button[@role='button']")
driver.execute_script("arguments[0].click();", element)
answered Sep 5, 2019 at 15:17
1
  • 1
    This is the only way I got the "click" working in my Python code. Thanks Commented May 27, 2021 at 22:43
2

Reason:
This is a known issue for some time now. https://github.com/SeleniumHQ/selenium/search?q=ElementClickInterceptedException&type=Issues This exception suggests that there is another element (div below the button) will receive the click.

Solutions:
1. Use another locator
2. Use Javascript executor driver.execute_script(JSCode,arguments)
e.g. driver.execute_script("arguments[0].click();", element) Takes your locator (element) as first argument and perform the action of click.
This action is equivalent to JQuery: $(locator).click

answered Sep 7, 2019 at 11:05
1
  • Great answer, @Sameer Wakude ! Thank you ! Commented Oct 17, 2022 at 20:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.