public boolean addNewAlertIsDisplayed() {
if(driver.findElement(By.xpath("//*[@class='aside right am-slide-right']")).isDisplayed()) {
return true;
}
else {
return false;
}
}
I am expecting false if it is not there..
But getting:
org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //*[@class='aside right am-slide-right'] (WARNING: The server did not provide any stacktrace information)
Why this exception is coming.. Is this needs to be handled in try/catch?
try-catch{}findElement should not be used to look for non-present elements, use findElements(By) and assert zero length response instead.See link..findElement()and atry-catch()... which is contrary to best practices and guidelines mentioned above.