步骤1:创建一个判断类
package Help;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class HaveOrNo {
public Boolean check(WebDriver driver,By seletor) {
try {
driver.findElement(seletor);
return true;
} catch (Exception e) {
// TODO: handle exception
return false;
}
}
}
步骤2:然后调用
HaveOrNo checkElement=new HaveOrNo();
By seletor=new By.ByXPath("//*[@id="signup-form"]/div[3]/input") ;
driver.manage().window().maximize();
if(checkElement.check(driver, seletor)) {
//此元素存在
}
else{
//此元素不存在
}
最后
以上就是微笑猎豹最近收集整理的关于selenium+java 判断元素是否存在的全部内容,更多相关selenium+java内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复