isDisplayed() method to verify the web element is present or not

isDisplayed() is used to verify the web element is present on the web page. isDisplayed method is boolean type.  It will return a boolean value whether its true or false.

JAVA API Syntax : boolean isDisplayed()

Below code is an example to verify the login button web element is present on the web page.

Code:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class isdisplayed {
 
public static void main(String args[]) {

//Launching the firefoxbrowser
WebDriver driver = new FirefoxDriver();
  
//Implicit wait, this method is used to wait for the webelement to load  
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);  
  
//Navigate to FB page
driver.get("http://www.facebook.com");
  
//Assign the loginbutton element to the variable
WebElement loginbutton = driver.findElement(By.id("loginbutton"));
  
//Assign the login button in boolean variable to check whether the element is present
boolean boolloginbutton = loginbutton.isDisplayed();

//check the conditions is true in if statement  
if(boolloginbutton == true)
{
    System.out.println("Login Button is present");
}
else
{
    System.out.println("Login Button is NOT present");
}
}
}
Output:
Login Button is present
Socialize It and Share the post with your friends
SOCIALIZE IT →
FOLLOW US →
SHARE IT →