断言网页中缺少元素,给出NoSuchElementException [英] Assert Absence of element in the web page, giving NoSuchElementException
本文介绍了断言网页中缺少元素,给出NoSuchElementException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要声明网页中没有这样的元素,
尝试使用 fieldValueBox.isDisplayed();
而不是false时抛出 NoSuchElementFound异常。
现在我正在使用'try catch'并在'catch'中做出决定
Need to assert that there is no such element in the webpage,
When tried with fieldValueBox.isDisplayed();
instead of "false" its throwing "NoSuchElementFound" exception.
Right now i was using 'try catch' and making decision in 'catch'
推荐答案
如果元素不是在页面上,然后你会得到'NoSuchElementFound'异常。您可以尝试检查定位器的元素数量是否为零:
If the element is not on the page, then you will get 'NoSuchElementFound' exception. You can try checking that the number of elements with the locator is zero:
private boolean elementNotOnPage(){
boolean elementIsNotOnPage = false;
List<WebElement> element = driver.findElements(yourLocator);
if(element.size() == 0){
elementIsNotOnPage = true;
}
return elementIsNotOnPage;
}
这篇关于断言网页中缺少元素,给出NoSuchElementException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文