com.thoughtworks.selenium.SeleniumException:未知错误:元素无法点击

时间:2015-01-10 04:58:02

标签: selenium selenium-chromedriver

环境 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 + \“)”);

但它对我有用。 提前致谢

1 个答案:

答案 0 :(得分:0)

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

您可以使用以下代码:

//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());
}