0

We have IsDisplayed() method created in our framework at lib class:

public static boolean isDisplayed()(WebElement locator){

try{
return locator.isDisplayed();
}catch (Exception e){
return false;
}
}

This is the WebElement:

public WebElement icon(String rootnumber){
WebElement e=driver.findElement.(By.xpath("//div[@row_id='"+rootnumber+"']//following-sibling::span[@matbadgecolor='warn']"));
return e;
}

So inside a method, I tried to print boolean value of icon like this:

System.out.println("Boolean value of icon presence is "+lib.isDisplayed(icon("123456789")));

It gives me NoSuchElementException error at this sysout command instead of printing boolean value.

1 Answers1

0

You were almost there. But while dealing with xpath the function is following-sibling().

So you just need to replace foolowing-sibling with following-sibling and your effective code block will be:

public WebElement icon(String rootnumber){
WebElement e=driver.find(By.xpath("//div[@row_id='"+rootnumber+"']//following-sibling::span[@matbadgecolor='warn']"));
return e;
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352