selenium工具
直接通過findElement方法獲取某個元素,如果該元素不存在肯定會報錯,selenium又沒有可以判斷該元素是否存在的方法
於是我們可以手寫一個工具類,來判斷這個元素是否存在
selenium的使用這里推薦一個學習網站 http://www.testclass.net/selenium_java/install-java
/**
* 判斷某個元素是否存在
*/
public boolean isJudgingElement(WebDriver webDriver, By by) {
try {
webDriver.findElement(by);
return true;
} catch (Exception e) {
System.out.println("不存在此元素");
return false;
}
}