Debugging “Element is not clickable at point” error

后端 未结 30 2108
余生分开走
余生分开走 2020-11-21 23:55

I see this only in Chrome.

The full error message reads:

\"org.openqa.selenium.WebDriverException: Element is not clickable at point (411, 675

相关标签:
30条回答
  • 2020-11-22 00:19

    I had the same issue, tried all offered solutions but they did not work for me. eventually I used this:

    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("var evt = document.createEvent('MouseEvents');" + "evt.initMouseEvent('click',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);" + "arguments[0].dispatchEvent(evt);", findElement(element));
    

    Hope this helps

    0 讨论(0)
  • 2020-11-22 00:19

    Re Tony Lâmpada's answer, comment #27 did indeed solve the problem for me, except that it provided Java code and I needed Python. Here's a Python function that scrolls to the element's position and then clicks it.

    def scroll_to_and_click(xpath):
        element = TestUtil.driver.find_element_by_xpath(xpath)
        TestUtil.driver.execute_script('window.scrollTo(0, ' + str(element.location['y']) + ');')
        element.click()
    

    This solved the problem for me in Chrome 34.0. It caused no harm in Firefox 28.0 and IE 11; those browsers aren't subject to the problem, but scrolling to the element's position before clicking it still isn't a bad thing.

    0 讨论(0)
  • 2020-11-22 00:19

    I do a kind of brute force of clicks and it works for me.

    try:
        elem.click()
    except:
        print "failed to click"
        size = elem.size
        mid_of_y = int(size["height"])/2
        stepts_to_do_to_left = int(size["width"])
        while stepts_to_do_to_left > 0:
            try:
                print stepts_to_do_to_left, mid_of_y
                action = webdriver.common.action_chains.ActionChains(driver)
                action.move_to_element_with_offset(elem, mid_of_y, stepts_to_do_to_left)
                action.click()
                action.perform()
                print "DONE CLICK"
                break
            except:
                pass
    
    0 讨论(0)
  • 2020-11-22 00:21

    You can also use JavaScript click and scrolling would be not required then.

    IJavaScriptExecutor ex = (IJavaScriptExecutor)Driver;
    ex.ExecuteScript("arguments[0].click();", elementToClick);
    
    0 讨论(0)
  • 2020-11-22 00:24

    You need to use focus or scroll on that element. You also might have to use explict wait.

    WebElement firstbutton= driver.findElement(By.xpath("Your Element"));
    Actions actions = new Actions(driver);
    actions.moveToElement(element);
    actions.perform();
    

    OR

    The element is not clickable because of a Spinner/Overlay on top of it:

    By loadingImage = By.id("loading image ID");
    WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
    wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));
    

    OR

    Point p= element.getLocation();
    Actions actions = new Actions(driver);
    actions.moveToElement(element).movebyoffset(p.x,p.y).click().perform();
    

    OR

    If still not work use JavascriptExecutor

    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", firstbutton);
    
    0 讨论(0)
  • 2020-11-22 00:24

    If you have jQuery loaded on the page, you can execute the following javascript command:

    "$('#" + element_id + "').click()"
    

    Example using python executor:

    driver.execute_script("$('#%s').click()" % element_id)
    
    0 讨论(0)
提交回复
热议问题