【发布时间】:2011-09-25 03:54:45
【问题描述】:
如何通过 web 驱动检查元素是否存在?
使用 try catch 真的是唯一可行的方法吗?
boolean present;
try {
driver.findElement(By.id("logoutLink"));
present = true;
} catch (NoSuchElementException e) {
present = false;
}
【问题讨论】:
-
@Michael Freidgeim:在你指责某人写了一个重复的问题之前,请检查问题的创建日期以确定哪个是重复的。
-
我不怪你。这只是一种整理方式——将相似的问题联系在一起。参见Should I vote to close a duplicate question, even though it's much newer, and has more up to date answers?“如果新问题是更好的问题或有更好的答案,那么投票关闭旧问题作为新问题的副本。”
标签: java testing webdriver selenium-webdriver