WebDriver:检查元素是否存在? [英] WebDriver: check if an element exists?
本文介绍了WebDriver:检查元素是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查元素是否存在于网络驱动程序中?
How to check if an element exist with web driver?
是否真的使用try catch是唯一可行的方法?
Is using a try catch really the only possible way?
boolean present;
try {
driver.findElement(By.id("logoutLink"));
present = true;
} catch (NoSuchElementException e) {
present = false;
}
推荐答案
您可以选择:
driver.findElements( By.id("...") ).size() != 0
保存令人讨厌的尝试/捕获
Which saves the nasty try/catch
这篇关于WebDriver:检查元素是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文