我们在lib
类中创建了IsDisplayed()
方法:
public static boolean isDisplayed()(WebElement locator){
try{
return locator.isDisplayed();
}catch (Exception e){
return false;
}
}
这是一个web元素:
public WebElement icon(String rootnumber){
WebElement e=driver.findElement.(By.xpath("//div[@row_id='"+rootnumber+"']//following-sibling::span[@matbadgecolor='warn']"));
return e;
}
所以在一个方法中,我尝试像这样打印图标的布尔值:
System.out.println("Boolean value of icon presence is "+lib.isDisplayed(icon("123456789")));
它给我NoSuchElementException
错误在这个sysout
命令,而不是打印布尔值。
你差一点就成功了。但是在处理xpath时,函数是following-sibling()
.
foolowing-sibling
替换为following-sibling
,你的有效代码块将是:
public WebElement icon(String rootnumber){
WebElement e=driver.find(By.xpath("//div[@row_id='"+rootnumber+"']//following-sibling::span[@matbadgecolor='warn']"));
return e;
}