Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

You can find whether an element is displayed on screen using the isDisplayed() method of the WebElement interface. It returns a boolean: true if the element is visible to the user and false if it is present in the DOM but hidden. If the element is not present at all, Selenium throws a NoSuchElementException, so the call is usually wrapped in a try-catch or paired with an explicit wait.
When you call isDisplayed(), Selenium inspects the element's rendered state in the browser, not just its presence in the DOM. It considers an element hidden if any of these are true: the CSS is display:none, the CSS is visibility:hidden, the opacity is 0, or the element has zero width and height. In every other case the element is treated as displayed and the method returns true.
This makes isDisplayed() the standard way to confirm that a button, link, message, or field is actually visible before you click it or type into it. Reliable WebDriver scripts check visibility first so they fail with a clear reason instead of interacting with an element the user cannot see.
The safest pattern locates the element, then checks visibility inside a try-catch so a missing element does not crash the test. The Java example below verifies a search box is visible before typing into it.
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.NoSuchElementException;
// Assuming 'driver' is an initialized WebDriver instance
try {
WebElement searchBox = driver.findElement(By.name("q"));
if (searchBox.isDisplayed()) {
System.out.println("Element is displayed");
searchBox.sendKeys("Selenium");
} else {
System.out.println("Element exists but is hidden");
}
} catch (NoSuchElementException e) {
System.out.println("Element is not present in the DOM");
}The try-catch is essential: isDisplayed() only returns false for a hidden-but-present element. If the element is completely absent, findElement() throws NoSuchElementException before isDisplayed() runs.
On pages that load content asynchronously, an element may not be visible the instant the script reaches it. Instead of a bare isDisplayed() call, use WebDriverWait with ExpectedConditions.visibilityOfElementLocated, which polls until the element becomes visible or the timeout expires.
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
import java.time.Duration;
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(
ExpectedConditions.visibilityOfElementLocated(By.id("myElement"))
);
System.out.println("Element is now displayed: " + element.isDisplayed());To learn more about the different wait strategies, see the types of waits available in WebDriver.
The visibility check exists in every Selenium binding. In Python the method is is_displayed() and the pattern is identical.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
driver = webdriver.Chrome()
driver.get("https://www.example.com")
try:
element = driver.find_element(By.ID, "myElement")
if element.is_displayed():
print("Element is displayed")
else:
print("Element exists but is hidden")
except NoSuchElementException:
print("Element is not present in the DOM")
driver.quit()Selenium offers three related boolean state checks that are easy to mix up:
A robust test often combines them, for example confirming a submit button is both displayed and enabled before clicking.
Element visibility can differ between browsers and screen sizes: an element that renders on desktop Chrome may be pushed off-screen or hidden by a responsive layout on Safari or a mobile viewport. That is why isDisplayed() assertions should be validated across many environments, not just one local browser. TestMu AI lets you run your Selenium suites on a cloud of 3000+ real browsers and operating systems, so a visibility check that passes locally is confirmed on the exact browser and device combinations your users have. Running automation testing at this scale catches rendering and layout defects that a single-browser run would miss.
The isDisplayed() method is the standard way to check whether an element is visible on screen in Selenium. Remember that it returns false only for hidden-but-present elements and throws an exception for missing ones, so pair it with try-catch or an explicit wait for reliability. Combine it with isEnabled() and isSelected() for complete state checks, and validate across real browsers to catch layout-specific issues. To keep building your locator skills, see how to locate elements on a web page.
isDisplayed() returns false only when the element exists in the DOM but is hidden. If the element is not present at all, findElement() throws a NoSuchElementException before isDisplayed() ever runs, so you must wrap the call in a try-catch or use an explicit wait.
isDisplayed() checks whether an element is visible on screen. isEnabled() checks whether it is active and can be interacted with, such as a non-disabled button. isSelected() checks whether a checkbox, radio button, or dropdown option is currently selected.
Selenium checks CSS properties and dimensions. An element is treated as not displayed if it has display:none, visibility:hidden, opacity:0, or zero width and height. In every other case the element is considered visible and isDisplayed() returns true.
Use WebDriverWait with ExpectedConditions.visibilityOfElementLocated(locator). Selenium polls the DOM until the element is present and visible or the timeout expires, which is far more reliable than a bare isDisplayed() call on a dynamic, asynchronously loaded page.
Use ExpectedConditions.invisibilityOfElementLocated(locator) with WebDriverWait, which returns true when the element is hidden or absent. Relying on isDisplayed() alone is risky because a missing element throws an exception instead of returning false.
Yes. The visibility check exists in every Selenium binding: is_displayed() in Python, isDisplayed() in Java and JavaScript, and IsDisplayed in C#. The behavior and rules for what counts as displayed are the same across all languages.
KaneAI - Testing Assistant
World’s first AI-Native E2E testing agent.

TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance