Selenium-Debugging: Element is not clickable at point (X,Y)
Asked Answered
N

9

84

I try to scrape this site by Selenium.

I want to click in "Next Page" buttom, for this I do:

driver.find_element_by_class_name('pagination-r').click()

it works for many pages but not for all, I got this error

WebDriverException: Message: Element is not clickable at point (918, 13). Other element would receive the click: <div class="linkAuchan"></div>

always for this page

I read this question

and I tried this

driver.implicitly_wait(10)
el = driver.find_element_by_class_name('pagination-r')
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(el, 918, 13)
action.click()
action.perform()

but I got the same error

Naquin answered 17/6, 2016 at 10:18 Comment(1)
When I go to that page there is no element with the class name, pagination-r or linkAuchan. I guess the page has changed?Hatband
C
209

Another element is covering the element you are trying to click. You could use execute_script() to click on this.

element = driver.find_element_by_class_name('pagination-r')
driver.execute_script("arguments[0].click();", element)
Coker answered 17/6, 2016 at 11:21 Comment(4)
@Coker what is the meaning of arguments[0] here?Gregorygregrory
@chandresh The execute_script() method has 2 parameters. The first is the script, the second is a vararg in which you can place any parameters used in the script. In this case we only need the element as parameter, but since it is a vararg our element is the first in the collection. For example you could also do driver.execute_script("arguments[0].click(); arguments[1].click();" element1, element2) This would click both elements passedCoker
Bear in mind, if you are writing tests that intend to use the website like a real user you are potentially doing something that a real user cannot do because the element they want to click on is covered. Don't do this to just make your tests pass!Coxa
@Gregorygregrory driver.execute_script("arguments[0].click();", element) - arguments[0] is element. You can do driver.execute_script("arguments[0].click();doSmthElse(arguments[1])", element, doSmthElseParam) and in this case arguments[1] would be doSmthElseParamTaxeme
M
31

Because element is not visible on the browser, first you need to scroll down to the element this can be performed by executing javascript.

element = driver.find_element_by_class_name('pagination-r')
driver.execute_script("arguments[0].scrollIntoView();", element)
driver.execute_script("arguments[0].click();", element)
Mccloud answered 26/1, 2021 at 1:56 Comment(3)
arguments[0].scrollIntoView(); is crucially missing from the currently accepted answer. This works perfectly.Nephrotomy
arguments[0].scrollIntoView() is crucial INDEED!!! This made my day, and helped me so much in 2022. Thank you,Bandur
driver.execute_script("arguments[0].scrollIntoView();", element) thank you so much about thisCaulfield
D
18

I had a similar issue where using ActionChains was not solving my error: WebDriverException: Message: unknown error: Element is not clickable at point (5 74, 892)

I found a nice solution if you dont want to use execute_script:

from selenium.webdriver.common.keys import Keys #need to send keystrokes

inputElement = self.driver.find_element_by_name('checkout')

inputElement.send_keys("\n") #send enter for links, buttons

or

inputElement.send_keys(Keys.SPACE) #for checkbox etc
Domiciliary answered 17/10, 2017 at 8:4 Comment(3)
can we click too after sending keys??Puca
@AbhishekGupta - The idea is that we can use keystrokes to simulate the action like link click or button click etc. - Instead of using the mouse. What is your scenario where you need both?Domiciliary
Everything else was not working in my case (a checkbox). Sending Keys.SPACE worked like as magic.Wapiti
T
3

I have written logic to handle these type of exception .

   def find_element_click(self, by, expression, search_window=None, timeout=32, ignore_exception=None,
                       poll_frequency=4):
    """It find the element and click then  handle all type of exception during click

    :param poll_frequency:
    :param by:
    :param expression:
    :param timeout:
    :param ignore_exception:list It is a list of exception which is need to ignore.
    :return:
    """
    if ignore_exception is None:
        ignore_exception = []

    ignore_exception.append(NoSuchElementException)
    if search_window is None:
        search_window = self.driver

    end_time = time.time() + timeout
    while True:
        try:
            web_element = search_window.find_element(by=by, value=expression)
            web_element.click()
            return True
        except tuple(ignore_exception) as e:
            self.logger.debug(str(e))
            if time.time() > end_time:
                self.logger.exception(e)
                time.sleep(poll_frequency)
                break
        except Exception as e:
            raise
    return False
Thready answered 30/5, 2020 at 6:3 Comment(3)
It is more efficient than other available option . Us ElementClickInterceptedException in ignore_exception list .Thready
very good solution! I have added ElementClickInterceptedException and ElementNotInteractableException in the ignore_exception, set timeout to 3 seconds, and works like a charm.Filbert
I still get the same error after using the above.Business
R
2

If you are receiving an element not clickable error, even after using wait on the element, try one of these workarounds:

  • Use Action to move to the location of element and then run perform on action
WebElement element = driver.findElement(By("element_path"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform();`
  • Check for an overlay or spinner on the element and wait for its invisibility
By spinnerimg = By.id("spinner ID");
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(ExpectedConditions.invisibilityOfElementLocated(spinnerimg ));

Hope this helps

Rance answered 27/2, 2020 at 2:12 Comment(1)
you can use markdown to format the code in your answer, which enhances readability. For example: WebElement element = driver.findElement(By("element_path")); Just wrap the code with the backtick character: `Jochbed
B
0

Use explicit wait instead of implicit.

new WebDriverWait(TestingSession.Browser.WebDriver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists((By.ClassName("pagination-r'")))); 
Bigner answered 17/6, 2016 at 12:30 Comment(3)
Can you rewrite it in python pleaseNaquin
Sorry dude. I never worked on python, though you can get help on explicit waits in python.Bigner
ExpectedConditions.ElementExists will not be helpful in this case. Element has been found but is not clickableVenice
S
0

I had the similar issue with Chrome driver, changing the PageLoadStrategy of chromeOptions from 'Eager' to Normal fixed my problem.

chromeOptions.PageLoadStrategy = PageLoadStrategy.Normal;
Siouxie answered 21/6, 2022 at 14:7 Comment(0)
W
0

Just as a heads up, we were having this problem because we were doing .click() on a Submit element. You can do .click() on Button OR .submit() on Submit, one of the two, but you shouldn't mix up these two methods.

.click() .submit()

Werth answered 5/3 at 14:11 Comment(0)
M
0

Met this issue. Had to add both scrollIntoView call to scroll element to visible part of the screen and explicit wait to wait for UI to finish scroll animation, then it worked.

Moonrise answered 17/4 at 9:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.