【发布时间】:2014-08-15 00:29:43
【问题描述】:
我一直在使用 Selenium WebDriver。我想等到该元素出现在我正在使用的网页上:
WebDriverWait wait = new WebDriverWait(driver, Long.parseLong(timeout));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator)));
但是如果我正在寻找的元素不存在甚至超过超时,我的测试就会卡在第二行。请帮忙。谢谢。
【问题讨论】:
-
根据文档,
visibilityOfElementLocated()查找“给定元素是否可见且大小不为零”。可见性基于样式属性。你的超时时间是多久?你等了多久?如果你只尝试WebElement ele = ExpectedConditions.visibilityOfElementLocated(By.xpath(locator));,你会得到什么? -
我成功了。我将超时从 60000 更改为 60,因为它将第二个参数作为秒而不是毫秒。
标签: selenium selenium-webdriver webautomation