How does Selenium isDisplayed() method work?

Related Product On This Page 1. isDisplayed () in Selenium

April 17, 2026 · 7 min read · Tool Comparison
Related Product

How perform Selenium isDisplayed () method work?

Selenium has be the number one alternative for automation examiner to test their web applications; and why not as it is open source, freely usable, endorse cross-browser, cross-platform and multiple programming lyric. It offer numerous built-in methods that simplify automation tasks, saving worthful clip.

Among these, the methods isDisplayed (), isSelected (), andisEnabled ()of the WebElement interface are widely used to verify the presence of elements on a web page.

Overview

Selenium ply built-in WebElement methods —isDisplayed (), isSelected (), and isEnabled ()— to validate whether ingredient are seeable, selectable, or active before performing any action. These checks prevent flaky handwriting and improve test reliability.

isDisplayed () in Selenium

  • Purpose: Checks if an element is visible on the page.
  • Logic: Evaluates CSS properties likedisplay, profile, and opacity.
  • Return: trueif seeable, elsefalse.
  • Use Case: Verify buttons, links, or fields are visible before clicking/typing.

isSelected () in Selenium

  • Purpose: Checks if a radio button, checkbox, or dropdown pick is selected.
  • Return: trueif take, elsefalse.
  • Use Case: Prevents re-selecting/deselecting unintentionally, especially in form mechanization.

isEnabled () in Selenium

  • Purpose: Determines if an element is active and interactive.
  • Return: true if enabled, else mistaken.
  • Use Case: Ensures activity (click, type) only occur on enabled elements, avoiding exclusion.

This article explains how the Selenium isDisplayed () method works in particular.

1. isDisplayed () in Selenium

The isDisplayed ()method of WebElement interface is used to check whether the element is visible or not on the web page. It retrovert a boolean value true if the element is visible and mistaken in either instance.

Now if you are enquire how Selenium finds that a give component is visible or not, let me excuse that as well. Selenium interacts with the DOM (Document Object Model) of the web page and when question forisDisplayed (), it control the constituent ’ s CSS properties like visibility, show and opacity to control its visibility.

If the factor has CSS property “visibleness: hidden”, or “display: none” or opacity is set to 0 so Selenium considers it as not displayed and returns false and in either case it returns true.

For example, consider home page and open inspect element page.

You may notice that the top bar factor hasstyle= ” display: none; ”. If you assert theisDisplayed ()value for this element, it will revert false.

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

importorg.openqa.selenium.By;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.WebElement;importorg.openqa.selenium.chrome.ChromeDriver;public classIsDisplayed {public static voidindependent (String [] args)throwsInterruptedException {WebDriver driver =newChromeDriver (); driver.get (`` https: //www.browserstack.com/ ''); WebElement nav=driver.findElement (By.cssSelector(`` nav.ds__top-bar ''));booleanflag=nav.isDisplayed (); System.out.println (`` Nav constituent is displayed: `` +flag);}}

Similarly, to check the visibility of “ Get Started ” button in following is the code:

public static voidchief (String [] args)throwsInterruptedException {WebDriver driver =newChromeDriver (); driver.get (`` https: //www.browserstack.com/ ''); WebElement getStarted=driver.findElement (By.cssSelector(`` a # signupModalProductButton ''));booleanflag=getStarted.isDisplayed (); System.out.println (`` Get Started button is exhibit: `` +flag);}}

isDisplayed () method should be used in mechanization scripts to verify the presence of any web element on the web page before performing any action on it, such as clicking, mail keys, hovering, etc. Using this method assure that the automation script is interacting with the seeable component entirely and hence reduces flaky resultant or false negatives.

2. isSelected () in Selenium

The isSelected () method in Selenium too belongs to the WebElement interface which is apply to determine if a web element such as tuner button or checkbox is selected or not. It revert a boolean value as true if the web element is selected and false if it is not selected.

Automating web forms is one of the common and typical scenario which involves snap tuner buttons, checkboxes and take an option from drop-downs. And before selecting any radio button or checkbox it is necessary to assure the current state of the constituent as being choose or not. For illustration, consider a use case which says to select a radio button.

In case if it is already choose; then selecting the radio button will actually deselect the tuner button and hence doing the reverse of what was expected. To avoid such mistakes, it is always better to check the current state of the web constituent before selecting/ deselecting it.

Below code demonstrates how to find the isSelected value for a wireless button before and after selecting expendW3Schools.com.

public classIsSelected {public static voidmain (String [] args)throwsInterruptedException {WebDriver driver =newChromeDriver (); driver.get (`` https: //www.w3schools.com/tags/tryit.asp? filename=tryhtml5_input_type_radio ''); driver.switchTo () .frame (`` iframeResult ''); Thread.sleep(2000); WebElement htmlRdBtn=driver.findElement (By.cssSelector(`` input # html '')); //isSelected () value before select radiocommunication pushbooleanflag=htmlRdBtn.isSelected (); System.out.println (`` HTML tuner push is selected: `` +flag); htmlRdBtn.click (); //isSelected () value after selecting radio buttonbooleanflag1=htmlRdBtn.isSelected (); System.out.println (`` HTML radio button is take: `` +flag1);}}

3. isEnabled () in Selenium

isEnabled () method is a built-in method provided by Selenium ’ s WebElement interface to determine whether the web constituent is enable or disabled on a web page. It returns a boolean value true if the element is enabled or false in either case. When a web element is disabled, it appears grayed out and non-interactive as it can not obtain any user activity such as clicking, selecting or typing.

isEnabled () method can help in automation by asserting the province of the element before performing any user action on it. Which entail that before do any event on the web element it is recommended to verify the province of the web element as enabled or disabled to deflect exceptions in the script.

Below code demonstrates how to find the isEnabled value for a button usingW3Schools.com.

Navigate tohttps: //www.w3schools.com/jsref/tryit.asp? filename=tryjsref_pushbutton_disabled2, open inspect constituent window and observe that “ My Button ” has no attribute as enabled=false or disabled and hence it is enabled.

Next, chink on the “ Try It ” button and so check the status of the “ My Button ”. Below code shew the same.

public classIsEnabled {public static voidmain (String [] args)throwsInterruptedException {WebDriver driver =newChromeDriver (); driver.get (`` https: //www.w3schools.com/jsref/tryit.asp? filename=tryjsref_pushbutton_disabled2 ''); driver.switchTo () .frame (`` iframeResult ''); Thread.sleep(2000); WebElement myBtn=driver.findElement (By.cssSelector(`` button # myBtn '')); //isEnabled () value before clicking try it buttonbooleanflag=myBtn.isEnabled (); System.out.println (`` My Button is enable: `` +flag); WebElement tryBtn=driver.findElement (By.xpath(`` //button [text () ='Try it '] '')); tryBtn.click (); //isEnabled () value after clicking try it buttonbooleanflag1=myBtn.isEnabled (); System.out.println (`` My Button is enabled: `` +flag1);}

Comparison between isDisplayed (), isSelected () & amp; isEnabled ()

Here ’ s the difference between isDisplayed (), isSelected () and isEnabled () in Selenium:

MethodPurposeSyntaxReturn valueWhen to Use
isDisplayed ()Determines the profile of the web elementboolean isDisplayed ()true if element is visible, mistaken if not seeableIt is used to check the visibility of web elements before performing any action on it
isSelected ()Determine if the web component is selected or notboolean isSelected ()true if element is selected, false if not selectedIt is apply to ascertain the position of checkbox, radio buttons or dip downs before performing any activeness on it
isEnabled ()Check if the web element is enabledboolean isEnabled ()true if element is enable, mistaken if disabledIt is used to check the state of the web element as enabled or handicapped before performing any action on it

Why use BrowserStack Automate for Selenium Tests?

Here ’ s why you should run your Selenium Tests on Existent Devices and Browsers using:

  • Parallel Testing: Parallel testing is paramount in reducing overall execution clip as it allows testers to execute scripts simultaneously on multiple devices/browsers. Automate platform provision this feature by giving admittance to latest device and browser for the testers to examine their coating.
  • Real device and browsers: A genuine user experience can only be achieved after testing the coating on real devices and browser. Testing on imitator and simulators can be easy, however it may not give exact test results at all time with respect to functional and even non-functional testing such as application ’ s execution.
  • Dedicated Dashboard:After bunk Selenium test cases on Automate product, it creates a report in a dashboard which can be referred to manage and monitor the mechanization quiz activities. It include an overview of the prove status as Pass/Fail/Pending with all the environs point such as device name, OS version, Platform, browser gens, browser version, test execution time and length, screenshots, etc.
  • Custom Reports with Artifacts:In Automate, custom reports can be generate to provide detailed and customized reports for the automated test execution. With this characteristic it allows to customize the construction and substance of the report as per user ’ s need. It can include a immense range of test data such as test execution status, gimmick and browser constellation, tryout duration, picture recording, screenshots, etc.
  • Easy Integration with CI/CD Pipeline:Automate can be easily integrated with democratic CI/CD tools such as Jenkins, TeamCity, TravisCI. The squad can achieve quicker delivery cycle with great confidence in the reliability, execution and compatibility of the coating across different devices and platforms.

Talk to an Expert

Tags
16,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free