Verifying whether an element present or visible in selenium Webdriver

+4 votes

How to verify element

  1. ispresent
  2. isvisible
  3. isenable
  4. textpresent
Apr 17, 2018 in Selenium by Vardy
• 2,250 points
15,717 views

3 answers to this question.

+3 votes
Best answer

Below code will help you:

  1. To check Element Present:

if(driver.findElement(By.xpath("value"))!= null){

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

}else{

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

}

  1. To check Visible:

if( driver.findElement(By.cssSelector("a > font")).isDisplayed()){

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

}else{

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

}

  1. To check Enable:
  2. if( driver.findElement(By.cssSelector("a > font")).isEnabled()){
  3. System.out.println("Element is Enable");
  4. }else{
  5. System.out.println("Element is Disabled");

}

  1. To check text present
  2. if(driver.getPageSource().contains("Text to check")){
  3. System.out.println("Text is present");
  4. }else{
  5. System.out.println("Text is absent");

}

answered Apr 17, 2018 by king_kenny
• 3,650 points

selected Sep 25, 2018 by Priyaj
+3 votes
1. ispresent
answered Sep 25, 2018 by anonymous
Yup. As simple as it gets...
0 votes
To verify if element is present we use

1
ispresent
answered Sep 25, 2018 by Priyaj
• 56,900 points

Related Questions In Selenium

0 votes
1 answer

Check that the element is clickable or not in Selenium WebDriver

Use Selenium Waits: WebDriverWait ...READ MORE

answered Jun 12, 2018 in Selenium by Meci Matt
• 9,420 points
9,690 views
0 votes
1 answer

Verify that an element exist in Selenium 2 or not

If you are testing using JUnit and ...READ MORE

answered Aug 23, 2018 in Selenium by Meci Matt
• 9,420 points
169 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
771 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,015 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
719 views
0 votes
1 answer

Need some advise on the preferred element locators with Selenium WebDriver

Well let's not call it "Hierarchy". But, ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,650 points
103 views
0 votes
1 answer

How to select an Object by its class in Selenium?

When it comes to Selenium, XPath will ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,650 points
58 views