Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Verify Element Exists on Page (Selenium-WebDriver)


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;
}

}

Post a Comment

0 Comments