com.thoughtworks.selenium.SeleniumException:未知错误:元素不可单击

com.thoughtworks.selenium.SeleniumException:未知错误:元素不可单击,selenium,selenium-chromedriver,Selenium,Selenium Chromedriver,环境 Chrome:版本39.0.2171.95 Chrome驱动程序:2.13最新版本 Selenium Web驱动程序 我需要在文本框中输入密钥,然后单击enter按钮。脚本在IE和FF中运行良好。但说到chrome,我发现了一个错误 com.thoughtworks.selenium.SeleniumException:未知错误:元素在221191点不可单击。其他元素将收到单击: 我看到的一些解决方案正在使用 JavascriptExecutor驱动程序.executeScriptwind

环境 Chrome:版本39.0.2171.95 Chrome驱动程序:2.13最新版本 Selenium Web驱动程序

我需要在文本框中输入密钥,然后单击enter按钮。脚本在IE和FF中运行良好。但说到chrome,我发现了一个错误

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

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

JavascriptExecutor驱动程序.executeScriptwindow.scrollTo0,\+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());
}