Selenium executeScript有时失败

时间:2015-06-08 09:13:30

标签: selenium

我创建了以下功能来点击元素

private WebDriverWait wait;
public void clickElement(By element) throws InterruptedException {

    // wait element is clickable
    wait.until(ExpectedConditions.presenceOfElementLocated(element));

    // driver.findElement(element).click();
    ((JavascriptExecutor) driver).executeScript("arguments[0].click();", driver.findElement(element));

    waitForAjaxLoadScreenDisappear();
}

我们点击了数千个元素,但有时会发生随机错误:

arguments[0] is undefined Command duration or timeout: 223 milliseconds Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27 09:10:26' System info: host: 'linux-1au3', ip: '192.168.1.194', os.name: 'Linux', os.arch: 'amd64', os.version: '3.1.10-1.23.1-desktop', java.version: '1.7.0_21' Session ID: 471aca55-ae19-439e-aaa2-b2ba970a1252 Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=20.0}]

当wait.until完成时,如何定义arguments [0]?

1 个答案:

答案 0 :(得分:1)

通常按钮具有启用/禁用属性,因此除了声明它可见之外,您还可能想要检查它们是否可点击/启用...

您应该可以执行以下操作:

element.isEnabled()

然后你可能想要在与元素交互之前循环直到它......