Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click

前端 未结 8 1483
北恋
北恋 2020-11-21 04:08

I used explicit waits and I have the warning:

org.openqa.selenium.WebDriverException: Element is not clickable at point (36, 72). Other element wou

8条回答
  •  不知归路
    2020-11-21 05:02

    I ran into this error while trying to click some element (or its overlay, I didn't care), and the other answers didn't work for me. I fixed it by using the elementFromPoint DOM API to find the element that Selenium wanted me to click on instead:

    element_i_care_about = something()
    loc = element_i_care_about.location
    element_to_click = driver.execute_script(
        "return document.elementFromPoint(arguments[0], arguments[1]);",
        loc['x'],
        loc['y'])
    element_to_click.click()
    

    I've also had situations where an element was moving, for example because an element above it on the page was doing an animated expand or collapse. In that case, this Expected Condition class helped. You give it the elements that are animated, not the ones you want to click. This version only works for jQuery animations.

    class elements_not_to_be_animated(object):
        def __init__(self, locator):
            self.locator = locator
    
        def __call__(self, driver):
            try:
                elements = EC._find_elements(driver, self.locator)
                # :animated is an artificial jQuery selector for things that are
                # currently animated by jQuery.
                return driver.execute_script(
                    'return !jQuery(arguments[0]).filter(":animated").length;',
                    elements)
            except StaleElementReferenceException:
                return False
    

提交回复
热议问题