【发布时间】:2012-08-29 12:04:37
【问题描述】:
我正在尝试下面的代码,但它似乎不起作用...有人可以告诉我最好的方法吗?
public void verifyThatCommentDeleted(final String text) throws Exception {
new WebDriverWait(driver, 5).until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver input) {
try {
input.findElement(By.xpath(String.format(
Locators.CHECK_TEXT_IN_FIRST_STATUS_BOX, text)));
return false;
} catch (NoSuchElementException e) {
return true;
}
}
});
}
【问题讨论】:
-
作为替代方案,您可以使用“WebdriverBackedSelenium”并使用 selenium.isElementPresent("Locator");
-
首先 input.findElements(By.xpath("//xpath")).size() > 0 是比在 try..catch 中包装 findBy 更好的方法来验证元素的存在。第二件事是:“它不起作用”是什么意思?会挂吗?抛出异常?返回不正确的结果?
标签: java selenium-webdriver assertion verify