Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

Anyone can send me sample code on how to verify element

  1. ispresent
  2. isvisible
  3. isenable
  4. textpresent

in Selenium WebDrvier using Java

1 Answer

0 votes
by (62.9k points)

I use Java language, here are the snippets:

  • To check Element Present:

if(driver.findElements(By.xpath("value")).size() != 0){

System.out.println("Element is Present");

}else{

System.out.println("Element is Absent");

}

Or

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");

}

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium online training

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...