一、判断页面的元素是否存在
private boolean isElementPresent(By by) {
try {
chromeDriver.findElement(by);
return true;
}catch(NoSuchElementException e){
return false;
}
}
二、判断页面上元素的值/内容
(1)严格匹配:result.equals("")
(2)模糊匹配:result.startWith,result.endWith,result.contains
(3)正则表达式:result.matches(“正则表达式”)
举例:
String result=chromeDriver.findElement(By.id(“train_date”)).getText();
if(result.contains(“中国铁路”)) {
System.out.println(“成功”);
}else {
System.out.println(“失败”);
}
三、直接读取数据库的内容