isdisplay()抛出NoSuchElementException错误,而不是打印布尔值



我们在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;
}

最新更新