Verify Element Exists on Page (Selenium-WebDriver)
@Using FindElement method
public Boolean isElementExistsOnPage(String xpath) {
try {
driver.findElement(By.xpath(xpath)).isDisplayed();
return true;
} catch (NoSuchElementException e) {
return false;
}
}
@Using FindElements method
public Boolean isElementExistsOnPage(String xpath) {
List<WebElement> elements = driver.findElements(By.xpath(xpath));
if (elements.size() == 0) {
return false;
} else {
return true;
}
}
0 Comments