【发布时间】:2011-03-18 00:48:09
【问题描述】:
在我编写的测试中,如果我想断言页面上存在 WebElement,我可以做一个简单的操作:
driver.findElement(By.linkText("Test Search"));
如果存在就会通过,如果不存在就会爆炸。但现在我想断言链接确实 not 存在。我不清楚如何执行此操作,因为上面的代码不返回布尔值。
编辑这就是我想出自己的修复方法的方法,我想知道是否还有更好的方法。
public static void assertLinkNotPresent (WebDriver driver, String text) throws Exception {
List<WebElement> bob = driver.findElements(By.linkText(text));
if (bob.isEmpty() == false) {
throw new Exception (text + " (Link is present)");
}
}
【问题讨论】:
标签: java selenium-webdriver assertion