Sunday, 22 September 2013

IsElementPresent()

There are various reasons and essential for this special functionality for everyday selenium-users.

isElementPresent() // positive test case
#1
if(isElementPresent(By.cssSelector(Value)))
System.out.println("...");
else
System.out.println("..."); 

#2 
Checks the availability using size()
if(driver.findElements(By.id("Value)).size()>0)
{
   System.out.println("...");
}else 
{
   System.out.println("...");
}

!isElementPresent() // negative test case
if(!isElementPresent(By.xpath("Value")))
{
   System.out.println("...");
else
{
   System.out.println("...");
}


isDisplayed() - Alternate for isElementPresent()

isDisplayed() is used for verifying whether an element is available on the page or not.

driver.findElement(By.xpath(Value)).isDisplayed();

3 comments: