20

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)

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
GoekhanDev
  • 326
  • 2
  • 4
  • 20

11 Answers11

81

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.

Matt
  • 68,711
  • 7
  • 155
  • 158
user12215068
  • 834
  • 5
  • 4
  • 1
    For me using the driver.find_element_by_class_name("secondary-action").click() function in selenium wouldn't work, but using this suggested function did. Also have no idea why :) – Craig Jan 28 '20 at 03:56
  • I had a similar issue as @Craig but the funny thin is it was working by using the following. searchbox = driver.find_element_by_xpath('//*[@id="smartSearch"]') and then searchbox.click() but all of a sudden it stop working. Thanks for the share! – Jiraheta Oct 03 '20 at 05:08
  • If anyone knows why, don't hesitate to comment! I used tot use wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Display available']"))).click() and spend days debugging.. – Rafael Nov 12 '20 at 11:45
  • For the new selenium version this would be driver.find_element('xpath', 'paste xpath here'). The rest would be same. – Mohammad Haris Sep 20 '22 at 00:52
11

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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
4

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)
Intellect
  • 125
  • 7
2

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.

Gabriele
  • 737
  • 2
  • 8
  • 20
0

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

frianH
  • 7,295
  • 6
  • 20
  • 45
0

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)
David Buck
  • 3,752
  • 35
  • 31
  • 35
Vimath
  • 63
  • 8
0

I don't have enough rep to comment but the common reason for this error might be Selenium locates the element from DOM on screen and locate the x-y coordinates (300, 650) then clicks on them but if some changes takes place on screen in between the click duration, for example google ads or some pop-up then it's unable to click on it resulting in this exception

I'm just guessing if anyone has a proper explanation to pls share

Arfath Yahiya
  • 107
  • 12
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/29872427) – Flair Sep 20 '21 at 16:09
  • You do now have enough reputation to comment. So please delete this, if you consider it a non-answer. Otherwise please [edit] to turn it into an answer according to [answer]. Or at least provide a link to what you actually want to comment on.... – Yunnosch Sep 18 '22 at 07:40
0

I had the same problem too. But my problem was not with the element. The button was activated with href. I changed the code from

<a class="services-button"  href="desired url">

To

<a class="services-button"  onclick="location.href='{% url "desired url" %}'";">
0

This solution worked for me :

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Firefox(executable_path="")
driver.get("https://UrlToOpen")   
action = ActionChains(driver)

firstLevelMenu = driver.find_element_by_id("menu")
firstLevelMenu.click()

source : http://allselenium.info/mouse-over-actions-using-python-selenium-webdriver/

Abhinav
  • 329
  • 3
  • 8
0

"selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable ... "

This exception occurs when element is not found on a web page (When the element we are looking for is at bottom part of the page which is not loaded yet)

So we you can scroll the page using javascript and load complete page and

from selenium.webdriver.common.by import By
from selenium import webdriver

url = "YOUR URL"
SCROLL_PAUSE_TIME = 0.5
driver = webdriver.Chrome()
driver.maximize_window()
driver.get(url)

def scroll_page():
    i = 0
    while i < 5:
        # Scroll down to 500 pixel
        driver.execute_script("window.scrollBy(0, 500)", "")

        # Wait to load page
        time.sleep(SCROLL_PAUSE_TIME)

        # Will scroll only for 4 increments of 500px
        i += 1
Azhar Khan
  • 3,829
  • 11
  • 26
  • 32
-1

You could try:

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

This solution solved my problems when I faced similar issues.

Stamatis Tiniakos
  • 698
  • 1
  • 11
  • 33
  • 1
    This would be a better answer if you explained how the code you provided answers the question. – pppery Jul 05 '22 at 15:56
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 06 '22 at 06:18
  • You confirm the solution provided by https://stackoverflow.com/a/58378714/7733418 by quoting it in your post and stating that it solved your problem. I assume your posts purpose is to say "Thanks", for that post of a different user, becaue it is more elaborate and has even some explanation. By that contrast, your post is free of additional information. Please delete it or make the additional insight which you contribute more obvious by [edit] according to [answer]. Note that "Thanks" with out anything else is not considered an answer here. – Yunnosch Sep 18 '22 at 07:38