Selenium : Verify element - 1. ispresent 2. isvisible 3. isenable 4. textpresent
- To check Element Present:
Orif(driver.findElements(By.xpath("value")).size() != 0){ System.out.println("Element is Present"); }else{ System.out.println("Element is Absent"); }
if(driver.findElement(By.xpath("value"))!= null){ System.out.println("Element is Present"); }else{ System.out.println("Element is Absent"); }
- To check Visible:
if( driver.findElement(By.cssSelector("a > font")).isDisplayed()){ System.out.println("Element is Visible"); }else{ System.out.println("Element is InVisible"); }
- To check Enable:
if( driver.findElement(By.cssSelector("a > font")).isEnabled()){ System.out.println("Element is Enable"); }else{ System.out.println("Element is Disabled"); }
- To check text present
if(driver.getPageSource().contains("Text to check")){ System.out.println("Text is present"); }else{ System.out.println("Text is absent"); }
WebElement rxBtn = driver.findElement(By.className("icon-rx")); WebElement otcBtn = driver.findElement(By.className("icon-otc")); WebElement herbBtn = driver.findElement(By.className("icon-herb"));
Assert.assertEquals(true, rxBtn.isDisplayed()); Assert.assertEquals(true, otcBtn.isDisplayed()); Assert.assertEquals(true, herbBtn.isDisplayed());
6. driver.findelement(By.id("id1")).isDisplayed()
driver.findelement(By.id("id2")).sendkey("test");
Example :
protected boolean isElementPresent(By by)
{
try {
driver.findElement(by);
return true;
}
catch (NoSuchElementException e)
{
return false;
}
}
No comments:
Post a Comment