Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
385 views
in Selenium by
recategorized by
How can I verify if element is present or not in Selenium 2

1 Answer

0 like 0 dislike
by
selected by
 
Best answer

You may want to try something like this.

 

private enum ElementStatus{
VISIBLE,
NOTVISIBLE,
ENABLED,
NOTENABLED,
PRESENT,
NOTPRESENT
}
private ElementStatus isElementVisible(WebDriver driver, By by,ElementStatus getStatus){
try{
if(getStatus.equals(ElementStatus.ENABLED)){
if(driver.findElement(by).isEnabled())
return ElementStatus.ENABLED;
return ElementStatus.NOTENABLED; 
}
if(getStatus.equals(ElementStatus.VISIBLE)){
if(driver.findElement(by).isDisplayed())
return ElementStatus.VISIBLE;
return ElementStatus.NOTVISIBLE;
}
return ElementStatus.PRESENT;
}catch(org.openqa.selenium.NoSuchElementException nse){
return ElementStatus.NOTPRESENT;
}
}


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...