11
votes

I am currently working on a project which fills a form automatically. And the next button appears when the form is filled, that's why it gives me an error.

I have tried:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//input[@type='button' and @class='button']")))
Next = driver.find_element_by_xpath("//input[@type='button' and @class='button']")
Next.click()

HTML:

<span class="btn">
    <input type="button" value="Next" class="button" payoneer="Button" data-controltovalidate="PersonalDetails" data-onfieldsvalidation="ToggleNextButton" data-onclick="UpdateServerWithCurrentSection();" id="PersonalDetailsButton">
     </input>
     <div class="clearfix"></div>
</span>

ERROR:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (203, 530). Other element would receive the click: ... (Session info: chrome=76.0.3809.132)

6
Have you trid with javascript click()? - supputuri

6 Answers

38
votes

If the path of the xpath is right, maybe you can try this method to solve this problem. Replace the old code with the following code:

button = driver.find_element_by_xpath("xpath")
driver.execute_script("arguments[0].click();", button)

I solved this problem before, but to be honestly, I don't know the reason.

4
votes

This error message...

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (203, 530). Other element would receive the click: ... (Session info: chrome=76.0.3809.132)

...implies that the click() on the desired element was intercepted by some other element and the desired element wasn't clickable.


There are a couple of things which you need to consider as follows:

  • While using Selenium for automation using time.sleep(secs) without any specific condition to achieve defeats the purpose of automation and should be avoided at any cost. As per the documentation:

time.sleep(secs) suspends the execution of the current thread for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep time. The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal’s catching routine. Also, the suspension time may be longer than requested by an arbitrary amount because of the scheduling of other activity in the system.


Solution

To click on the button with value as Next you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.button#PersonalDetailsButton[data-controltovalidate='PersonalDetails']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='button' and @id='PersonalDetailsButton'][@data-controltovalidate='PersonalDetails']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
1
votes

I looked at the exact element that was causing it and it was a banner about consent/cookies. So at first, I made sure it clicked "OK" on the consent banner and then I clicked the other button that I needed. Hope it helps someone.

1
votes

i faced similar issues, the .click() always returns a Not clickable exception. the

driver.execute_script('arguments[0].click()', button)

does the magic. You can also use it to execute any other js script this way

script = 'your JavaScript goes here'
element = driver.find_element_by_*('your element identifier goes here')
driver.execute_script(script, element)
0
votes

It look's like there are some other elements which are having the same xpath try changing the xpath something like this

Next = driver.find_element_by_xpath("//input[@id='PersonalDetailsButton']");
Next.Click();

or

Next = driver.find_element_by_xpath(//input[@value='Next' and @id='PersonalDetailsButton']);
Next.Click();

Try first xpath if that doesn't work go with the second one . If that also doesn't work try using sikuli. I am pretty sure that first xpath will work

0
votes

I faced a similar issue and I observed something that might help to understand the root cause of the issue. In my case, I was able to click at an element being in PC view mode of the website but failed to do so in mobile view (in which I needed my script to run). I found out that in mobile view, ordering of elements (li in my case) changed in view while they remained same in the html document. That's why I was not able to click on it without actually scrolling to it first. It might also explain why this works: -

driver.execute_script("arguments[0].click();", button)