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

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

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 to verify whether the element is present on the webpage or disabled is given below.


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;
public class FacebookLogin {
     public static void main(String[] args) {
           // TODO Auto-generated method stub
           WebDriver driver=new ChromeDriver();
           //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