How to Use isDisplayed() in Selenium
Learn how Selenium’s isDisplayed() checks element visibility, when to wait for visibility, and why a displayed element may still not be clickable.
Call isDisplayed() on a Selenium WebElement after locating it. Java uses element.isDisplayed(), Python uses element.is_displayed(), and JavaScript uses await element.isDisplayed(). Each reports Selenium’s assessment of whether the element is displayed in the current browsing context. For a page that is still changing, wait for visibility with an explicit wait instead of checking once and assuming the state will persist.
1. What isDisplayed() checks
The method returns a Boolean in Java and Python; in JavaScript it returns a promise that resolves to a Boolean. Selenium describes displayedness as an approximation: the WebDriver specification does not define every condition, so Selenium evaluates the element and its relationship in the DOM tree. Treat true as Selenium’s displayedness assessment, not a guarantee that every user will perceive the element the same way.
The method answers a narrower question than “Can I interact with this element?” It does not establish that the element is enabled, unobstructed, within the viewport, or ready to accept a click or keystroke. See Selenium’s element information documentation.
2. Locate an element and check it
Use a locator appropriate to the page, find the element, then call the binding’s displayedness method. These examples show the typical syntax; adapt imports and setup to your Selenium version and project.
Python
from selenium import webdriver
from selenium.webdriver.common.by import By
# Assumes the page contains an element with id="submit".
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
button = driver.find_element(By.ID, "submit")
if button.is_displayed():
print("Selenium reports the element as displayed")
else:
print("Selenium reports the element as not displayed")
finally:
driver.quit()
The Python method is named is_displayed() with an underscore. Its return value is a bool. A missing element is different from a present but hidden element: find_element raises NoSuchElementException if it cannot locate a match.
Java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class DisplayedCheck {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
WebElement button = driver.findElement(By.id("submit"));
if (button.isDisplayed()) {
System.out.println("Selenium reports the element as displayed");
} else {
System.out.println("Selenium reports the element as not displayed");
}
} finally {
driver.quit();
}
}
}
Java’s method is isDisplayed() and returns primitive boolean.
JavaScript
const { Builder, By } = require('selenium-webdriver');
(async function checkDisplayed() {
const driver = await new Builder().forBrowser('chrome').build();
try {
await driver.get('https://example.com');
const button = await driver.findElement(By.id('submit'));
const displayed = await button.isDisplayed();
console.log(displayed
? 'Selenium reports the element as displayed'
: 'Selenium reports the element as not displayed');
} finally {
await driver.quit();
}
})();
In Selenium’s JavaScript binding, await the promise returned by isDisplayed(). See the JavaScript WebElement API.
3. Check once or wait for visibility?
A direct call reads the state at that moment. If a script, animation, route change, or delayed request may reveal the element later, wait for the state you need. A one-time call made too early can report false even though the element will appear shortly.
Python explicit wait for visibility
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
locator = (By.ID, "submit")
button = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located(locator)
)
# The returned element has met the visibility condition.
button.click()
The timeout is an example, not a performance recommendation. Selenium’s Python visibility_of_element_located condition waits for an element to be present in the DOM and have non-zero width and height. If the next action is a click, element_to_be_clickable additionally checks that it is enabled. Neither condition can guarantee the click center will remain unobscured at the instant of interaction. See the Python expected conditions API.
In Java and JavaScript, use the explicit-wait facilities available in your binding and wait for the condition your next step requires. Avoid tight loops that repeatedly query displayedness without a wait interval; they create needless WebDriver commands and can still race with page changes.
4. Displayed is not the same as clickable
Selenium performs further checks during element interactions. It may scroll an element into view, and it checks display and interactability. An element that is not displayed or not pointer- or keyboard-interactable can cause an element-not-interactable error. If another element covers the click’s center point, the click can instead fail with an element-click-intercepted error.
| Need | Use | What it tells you |
|---|---|---|
| Current displayedness | isDisplayed() / is_displayed() |
Selenium’s displayedness assessment at the time of the call. |
| Wait until visible | An explicit visibility condition | The element has reached the visibility condition before proceeding. |
| Check basic click readiness in Python | element_to_be_clickable |
The element is visible and enabled. |
| Verify a real action | Perform the interaction and handle its specific result | Whether the browser accepted that action under current viewport and obstruction conditions. |
For the interaction checks and related errors, consult Selenium’s interacting with web elements guide.
5. Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
NoSuchElementException |
The locator matched no element when the lookup ran, perhaps because the page is not ready or the locator is wrong. | Check the locator and browsing context. If content appears asynchronously, wait for presence or visibility before using the element. |
The check returns false, but the element appears later |
The check ran before a delayed render or transition completed. | Use an explicit wait for visibility rather than treating one immediate result as final. |
ElementNotInteractableException |
The element may not be interactable for the requested action, even if it was reported displayed. | Wait for the needed state, confirm the correct element was located, and inspect whether it is enabled and suitable for the action. |
ElementClickInterceptedException |
Another element obscures the click center, for example an overlay or transient dialog. | Wait for the obstruction to disappear or handle it as part of the page flow, then retry using a condition appropriate to the action. |
| JavaScript code does not get a Boolean immediately | isDisplayed() is asynchronous in the JavaScript binding. |
Await the call: const displayed = await element.isDisplayed();. |
| Python reports an attribute error for the method name | The Java-style capitalization was used in Python. | Call element.is_displayed(). |
6. Reliability and performance notes
- Use explicit waits for changing pages. They express the condition required by the next step and avoid acting on a stale assumption about the page.
- Keep locators specific. A check is only useful if it refers to the intended element, especially when a page contains hidden templates or duplicate controls.
- Do not use displayedness as a substitute for action handling. The page can change between the check and the click, and overlays can still intercept interaction.
- Avoid rapid polling loops you write yourself. Each WebDriver command adds browser-driver communication; use the binding’s wait utilities and a sensible timeout for the page’s expected behavior.
- Keep cleanup in a finally block. Quitting the driver releases the browser session even when locating or interacting with an element fails.
isDisplayed() itself does not determine a test’s cost. Runtime is typically shaped by browser startup, navigation, page behavior, and the number of remote WebDriver commands; no universal timing follows from the method’s Boolean result.
7. Capture the page for debugging
A screenshot can make a visibility or interception failure easier to inspect alongside the DOM and browser logs. You can capture the page with your existing browser automation setup, or use a screenshot API when you only need an image or PDF and do not need to configure a browser session.
8. Or skip the browser setup
For a page capture without managing a WebDriver session, ScreenshotNeo provides a website screenshot API and MCP server. The API accepts one GET request with a URL and returns PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation for parameters and options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
const fs = require('node:fs');
fs.writeFileSync('shot.webp', Buffer.from(await res.arrayBuffer()));
ScreenshotNeo accepts cookie and consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Every feature is on every plan.
Sign up for 1,000 free screenshots a month, with no card.
9. FAQ
Does isDisplayed() check the element’s CSS display property?
It reports Selenium’s overall displayedness assessment rather than simply parsing one style attribute. Selenium documents it as an approximation over the element and its relationship in the page tree.
Can an element be displayed but outside the viewport?
Displayedness alone does not establish viewport position or successful interaction. Selenium may scroll an element into view when interacting, but other interaction checks still apply.
Should I use isDisplayed() to decide whether an element exists?
No. First locate it or wait for its presence; displayedness describes a located element’s state. A failed lookup and a located-but-not-displayed element are different cases.
What is the JavaScript return type?
The JavaScript Selenium API returns a Promise<boolean>, so await it before branching on the result.


