com.thoughtworks.selenium.SeleniumException: unknown error: Element is not clickable

com.thoughtworks.selenium.SeleniumException: unknown error: Element is not clickable

环境 Chrome:版本 39.0.2171.95 Chrome 驱动程序:2.13(最新) Selenium WebDriver

我需要在文本框中输入密钥,然后单击输入按钮。脚本在 IE 和 FF 中运行良好。但是当涉及到 chrome 时,我发现错误

com.thoughtworks.selenium.SeleniumException:未知错误:元素在点 (221, 191) 不可单击。其他元素将收到点击:

我看到的一些解决方案正在使用

((JavascriptExecutor) 驱动程序).executeScript("window.scrollTo(0,\"+elementToClick.getLocation().y+\")");

但这对我来说很有效。 提前致谢

尝试等待元素可点击然后点击它。

您可以使用以下代码:

//Wait for 20 seconds to detect that the element is clickable, and then clicking on it
try{
    WebDriverWait wait = new WebDriverWait(driver, 20);
    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//xpath of the Enter button")));
    element.click();
}catch(Throwable e){
    System.err.println("Error while waiting for the element to be clickable: "+e.getMessage());
}