Italian Trulli

How to Check if Element is Present in Selenium using Java?

Test Tribe
.
Handling Elements Present or Not In Selenium 

 

How to Check if Element is Present in Selenium Java?

How To Check Element Is Present in Selenium


isDisplayed()
To check if an element (checkbox, dropdown, Button, Textbox, radio button, link, etc)  is present or visible on the page use the isDisplayed() method.
isDisplayed() is a method used to verify and return true if the specified element is displayed. Otherwise, it will return false.

Syntax:

Syntax to verify whether the element is present on the webpage or disabled is given below.

driver.findElement(By.id("Fname")).isDisplayed();

To check and verify the element's visibility on a webpage isDisplayed() Method is used. 

Selenium Code

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
 
import org.openqa.selenium.chrome.ChromeDriver;
 
public class FacebookLogin {
 
     public static void main(String[] args) {
           // TODO Auto-generated method stub
           System.setProperty("webdriver.chrome.driver""C:\\Software\\chromedriver.exe");
           WebDriver driver=new ChromeDriver();
           driver.get("https://www.facebook.com");
          
           //To verify that Element is Displayed
           Boolean nn =driver.findElement(By.xpath("//input[ @type=\"text\"]")).isDisplayed();
     if(nn) {
           System.out.println("Yes ! Element is Present");
     }
     else {
           System.out.println("NO ! Element is not Present");
     }
 
}
}


The above Selenium Code will Check whether the element is present or not. 

how to verify element is present in selenium

Post a Comment

0 Comments