Assert an element is not displayed throws and exception that is not catch in the caller block
I use this function from webdriverextensions for verify an element is not displayed assertIsNotDisplayed(driver().findElement ....)
The problem here is if the method do not finds the element, throws a NoSuchElementException that is ignoring the catch block.
public static boolean isDisplayed(WebElement webElement) {
try {
return webElement.isDisplayed();
} catch (NoSuchElementException e) {
return false;
}
}
public static void assertIsNotDisplayed(WebElement webElement) {
try {
if (isDisplayed(webElement)) {
throw new WebAssertionError(
"Element is displayed when it shouldn't", webElement);
}
} catch (final NoSuchElementException |
java.util.NoSuchElementException |
org.openqa.selenium.TimeoutException ignore) {}
}
On use this method on the test I get a NoSuchElementException but I was expecting the catch block to work.
What Im missing on java error handling ?