Here's an example of a wrapper method in Selenium that checks if an element is present on a webpage:
public boolean isElementPresent(By locator) {
try {
driver.findElement(locator);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
This method takes a locator and returns a boolean value indicating whether or not the element is present on the webpage. It wraps around the findElement method provided by Selenium and catches the NoSuchElementException to prevent the test from failing if the element is not found.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article