isDisplayed() for me will throw org.openqa.selenium.NoSuchElementException: Can’t locate an element by this strategy:… if the element is not present in the page.
I can only use it in assertion to validate it.
If I want to check if the element is not present and then continue the test I’m using this work around found here
public void checkIfElementIsPresent(MobileElement element1) {
WebDriverWait wait = new WebDriverWait(driver, 1);
try {
if (wait.until(ExpectedConditions.visibilityOf(element1)) != null) {
Assert.assertTrue(element1.isDisplayed());
//do something if present
}
} catch (Exception e) {
log.info("Element not present, we are good here!");
//do something if not present
// Assert.assertTrue(element2.isDisplayed());
}
}