Best Way of checking element not present in webpage using selenium webdriver ?
Often encountered a situation where you have to verify an element is not present in the web page.
using
try { driver.findElement(locatorKey); Assert.assertTrue(false); } catch (org.openqa.selenium.NoSuchElementException e) { Assert.assertTrue(true); }
is not a right approach. Because this is layman way of asserting absence of web element.
As per selenium documantaion, best way to check if element is not present is using findElements and then asseting on the size of the list returned.
findElements does not throw any exception in case if an element is not present. Asserting on 0 length is more appropriate for absence of an element.
Selenium official comment :
No comments:
Post a Comment