Also catch the NoSuchElementException if the element is not present in DOM thrown by findElement(locator) and return null in method visibilityOfElementLocated
@@ -203,7 +203,8 @@ public String toString() {
public WebElement apply(WebDriver driver) {
try {
return elementIfVisible(driver.findElement(locator));
- } catch (StaleElementReferenceException e) {
+ } catch (StaleElementReferenceException | NoSuchElementException e) {
+ // Returns null because the element is no longer or not present in DOM.
return null;
}
}
