0

我一直在使用 Selenium WebDriver。我想等到该元素出现在我正在使用的网页上:

    WebDriverWait wait = new WebDriverWait(driver, Long.parseLong(timeout));
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator)));

但是如果我正在寻找的元素不存在甚至超过超时,我的测试就会卡在第二行。请帮忙。谢谢。

4

2 回答 2

1

也许: - 元素存在,所以不会抛出异常 - 然后卡住,因为之后你没有做任何其他事情

until尝试在通话后打印 smt 。我的猜测是它会被打印出来。

否则可能是超时:它必须以秒为单位,而不是毫秒。

http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/WebDriverWait.html#WebDriverWait(org.openqa.selenium.WebDriver,长)

于 2014-06-24T17:20:27.740 回答
0

我搞定了。我将超时从 60000 更改为 60,因为它将第二个参数作为秒而不是毫秒。

于 2015-01-27T12:18:58.497 回答