The isDisplayed() method in Selenium WebDriver is used to check the visibility of a web element on the page. This method returns a boolean value (true or false) indicating whether the element is displayed. Understanding how to use the isDisplayed() method effectively is crucial for verifying that elements are visible to the user, which is important for ensuring that the web application behaves as expected.


// Assuming 'element' is an instance of WebElement
boolean isDisplayed = element.isDisplayed();


  1. Checking if an Element is Displayed:
WebElement element = driver.findElement("elementId")); 
boolean isElementDisplayed = element.isDisplayed();


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class IsDisplayedExample {
    public static void main(String[] args) {
        // Set path to the ChromeDriver executable
        System.setProperty("", "path/to/chromedriver");

        // Initialize ChromeDriver
        WebDriver driver = new ChromeDriver();

        // Open a webpage

        // Locate an element and check if it is displayed
        WebElement element = driver.findElement("submit"));
        boolean isElementDisplayed = element.isDisplayed();
        // Print the result
        System.out.println("Element displayed: " + isElementDisplayed);

        // Close the browser


  • Visibility Validation: The isDisplayed() method is essential for validating the visibility of elements on a webpage, ensuring that elements are visible to the user as expected.
  • Conditional Testing: It helps in performing conditional actions based on the visibility of elements, which is crucial for testing dynamic and interactive web applications.
  • Accurate Testing: By checking the visibility of elements, testers can ensure the accuracy and reliability of automated tests, particularly for elements that may be conditionally hidden or shown.


  • Visibility Only: The isDisplayed() method only checks if the element is visible. It does not check if the element is interactable (e.g., clickable or enabled).
  • CSS Influence: The visibility of an element can be affected by CSS properties such as display: none, visibility: hidden, or being off-screen. Ensure that these properties are considered when verifying element visibility.


The isDisplayed() method in Selenium WebDriver is a powerful tool for checking the visibility of web elements. It is essential for validating the visibility of elements, performing conditional testing, and ensuring the accuracy of automated tests. By mastering the use of the isDisplayed() method, testers can create robust and reliable automated scripts that accurately reflect and validate the visibility of elements in web applications.

Was this article helpful?
Leave a Reply 0

Your email address will not be published. Required fields are marked *