Select Class in Selenium [2026]

Related Product On This Page What is Select Class in Selenium?May 03, 2026 · 10 min read · Tool Comparison

Related Product

Select Class in Selenium [2026]

Most tester adopt employ theSelect class inis straightforward—find the dropdown, select a value, and move on. I suppose the same until a simple dropdown started failing without warn.

A examination that had be stable suddenly broke. I contribute waiting, pluck locater, rebroadcast the test repeatedly, and still wasted hour chasing the topic.

The problem wasn ’ t Selenium or the browser—it was how I washandling the dropdown.

Once I understood how theSelect class really works, those failures disappeared.

Overview

The Select grade in Selenium is designed specifically to interact with HTML & lt; select & gt; dropdown elements, providing built-in method to choose options reliably instead of rely on clicks or custom logic.

How to Use the Select Class (Quick Steps)

  • Locate the & lt; choice & gt; element using a Selenium locater
  • Create a Select target using that WebElement
  • Choose an selection using text, value, or power

Example Code (Java)

WebElement dropdown = driver.findElement (By.id (`` nation '')); Select choose = new Select (dropdown); select.selectByVisibleText (`` India '');

Common Select Class Methods

  • selectByVisibleText (String schoolbook) - selects the pick matching the displayed text
  • selectByValue (String value) & # 8211; selects the choice utilise the value property
  • selectByIndex (int index) & # 8211; selects the choice based on its position
  • getOptions () - retrovert all uncommitted dropdown options

Methods for Multi-Select Dropdowns

  • isMultiple () – checks if multiple option is allowed
  • selectByVisibleText () / selectByValue () – select multiple options
  • deselectAll () / deselectByVisibleText () – clear selected options

Limitations of the Select Class

  • Works only with native HTML& lt; blue-ribbon & gt; elements
  • Can not handle custom or JavaScript-based dropdowns
  • Requires a different approach for non-standard UI components

This article separate down how to use the Select class correctly and why it ’ s essential for honest dropdown handling in Selenium.

What is Select Class in Selenium?

In Selenium, the Select class cater the implementation of the HTML SELECT tag. A Prize tag provides the helper methods with select and deselect options. As Select is an ordinary grade, its object is create by the keyword New and also specifies the location of the web element.

Select Class Syntax in Selenium:

Prize objSelect = new Select ();

In the select grade syntax above, it distinctly express that Select class is asking for an element type object for its constructor, i.e it will create an object of the select class.

While the Select class simplifies interactions with standard HTML & lt; choice & gt; elements, dropdown deportment can still differ across browser and operating systems.

Verifying these interaction on real browser environments helps get issues that don ’ t appear topically.

Platforms like make it easier to run Selenium tests against real device and browsers, with logs and recordings that spotlight exactly how dropdowns behave during execution.

Struggling to manage Selenium dropdowns?

Flaky dropdowns fault tests. Validate Select grade interactions on real browser and device.

How to use Prime Class in Selenium?

Selenium offers Select Class which can be used to select value in the dropdown list. There are different method in the Select Class which can be used to do different actions in the dropdown element. It allow you to select the option based on its text, indicant, and value, select multiple selection, or deselect all.

According toSarah Thomas,an expert software tester, a common mistake is using the Select grade blindly on every dropdown. The well-nigh reliable approach is to initiative sustain the element is a native HTML & lt; select & gt; and so rely on Select family methods instead of custom clicks or workarounds, which helps keep Selenium tests stable and predictable.

Also Read:

Different Select Class Methods to handle Select Dropdown in Selenium

The following are the most commonly used select course methods in selenium to deal with a drop-down list:

1. selectByVisibleText: selectByVisibleText (String arg0): void

This blue-ribbon class method is employ to select one of the options in a drop-down box or an alternative among multiple selection boxes. It takes a argument of String which is one of the values of Select element and it returns nothing.

Syntax:

obj.Select.selectByVisibleText (“ text ”);

Example:

Select objSelect =new Select (driver.findElement (By.id (`` search-box ''))); objSelect.selectByVisibleText (`` Automation '');

2. selectByIndex: selectByIndex (int arg0): void

This method is similar to ‘selectByVisibleText’, but the dispute here is that the user has to ply the index routine for the option rather than text. It takes the integer parameter which is the indicator value of Select element and it revert cypher.

Syntax:

oSelect.selectByIndex (int);

Example:

Prize objSelect = new Select (driver.findElement (By.id (`` Seacrch-box ''))); Select.selectByIndex (4);

3. selectByValue: selectByValue (String arg0): void

This method asks for the value of the desired option rather than the choice text or an index. It takes a String parameter which is one of the values of Select element and it does not revert anything.

Syntax:

oSelect.selectByValue (“ text ”);

Example:

Select objSelect = new Select (driver.findElement (By.id (`` Search-box ''))); objSelect.selectByValue (`` Automation Testing '');

4. getOptions: getOptions (): List & lt; WebElement & gt;

This method acquire all the options belonging to the Select tag. It direct no parameter and return List & lt; WebElements & gt;.

Syntax:

oSelect.getOptions ();

Example:

Blue-ribbon objSelect = new Select (driver.findElement (By.id (`` Search-box ''))); List & lt; WebElement & gt; elementCount = oSelect.getOptions (); System.out.println (elementCount.size ());

5. getFirstSelectedOption ()

This method helps fetch the first select option from the dropdown. It is especially usefyl while work with multi-select dropdowns, where you can select multiple options. This method revert the maiden select option as a WebElement.

Syntax:

oSelect.getFirstSelectedOption ();

Example:

Prime objSelect = new Select (driver.findElement (By.id (`` country ''))); WebElement firstOption = objSelect.getFirstSelectedOption (); System.out.println (firstOption.getText ());

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

6. getAllSelectedOptions ()

This method fetches all choose alternative in a multi-select dropdown. It returns of list of all selected options as List & lt; WebElement & gt;.

Syntax:

oSelect.getAllSelectedOptions ();

Example:

Select objSelect = new Select (driver.findElement (By.id (`` science ''))); List & lt; WebElement & gt; selectedOptions = objSelect.getAllSelectedOptions (); for (WebElement choice: selectedOptions) {System.out.println (option.getText ());}

7. deselectAll ()

This method aid deselect all selected pick in a multi-select dropdown. If called on a single-select dropdown, it throws an exception.

Syntax:

oSelect.deselectAll ();

Example:

Select objSelect = new Select (driver.findElement (By.id (`` languages ''))); objSelect.deselectAll ();

8. deselectByIndex

This method can be used in a multi-select dropdown to deselect an option at the specified index. It conduct an integer parameter and returns zippo.

Syntax:

oSelect.deselectByIndex (int);

Example:

Select objSelect = new Select (driver.findElement (By.id (`` line ''))); objSelect.deselectByIndex (2);

9. deselectByValue

This method is used to deselect an option according to the value attribute of the option tag. It lead a twine parameter and return zip.

Syntax:

oSelect.deselectByValue (`` value '');

Example:

Select objSelect = new Select (driver.findElement (By.id (`` cities ''))); objSelect.deselectByValue (`` blr '');

10. deselectByVisibleText

This is use to deselect the option displaying the specified visible text. It takes a string argument and return zero.

Syntax:

oSelect.deselectByVisibleText (`` text '');

Example:

Select objSelect = new Select (driver.findElement (By.id (`` fruits ''))); objSelect.deselectByVisibleText (`` Apple '');

How to Select multiple items in Dropdown with the Select command?

The multiple quality dimension is a boolean expression. This method fix that multiple options can be selected at erst. These selection vary for different operating systems and browser.

  • For Windows: Press the control (ctrl) push to choose multiple options.
  • For Mac: Hold down the command push to select multiple options.

Use the isMultiplemethod to take multiple command.

isMultiple (): boolean– This method informs whether the Select element back multiple choice pick at the like clip or not. This method accept nothing and returns a boolean value (true/false).

Syntax:

objSelect.isMultiple ();

Example:

Select objSelect = new Select (driver.findElement (By.id (Element_ID))); objSelect.selectByIndex (power); objSelect.selectByIndex (index); // Or can be used as objSelect.selectByVisibleText (text); objSelect.selectByVisibleText (text); // Or can be used as objSelect.selectByValue (value); objSelect.selectByValue (value);

Now let ’ s expression at a real-time example of the prime bid.

Read More:

How to Select Value from Dropdown in Selenium utilize Select Class: with Example

In this example, let ’ s explore how to select a value in a drop-down leaning using the Select class in Selenium.

import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; importation org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.Select; public class SelectExample {@ Test public stable vacancy principal (String [] args) throws InterruptedException {System.setProperty (`` webdriver.chrome.driver '', `` Path_of_Chrome_Driver ''); WebDriver driver = new ChromeDriver (); driver.get (`` https: //www.browserstack.com/ ''); driver.manage () .window () .maximize (); WebElement developers_dropdown = driver.findElement (By.id (`` developers-menu-toggle '')); Select objSelect = new Select (developers_dropdown); objSelect.selectByIndex (2); Thread.sleep (3000); driver.navigate (`` https: //www.browserstack.com/ ''); WebElement solutions_dropdown = driver.findElement (By.id (`` solutions-menu-dropdown '')); Select solutions = new Select (solutions_dropdown); solutions.selectByValue (`` 4000 ''); Thread.sleep (3000); WebElement solutions_d = driver.findElement (By.id (`` solutions-menu-dropdown '')); Select s1 = new Select (solutions_d (); s1.selectByVisibleText (`` Geolocation Testing '');}}

The code above will direct Selenium to navigate to the and choose the value from the drop-down lists available on the Developers and Solutions tabs as shown in the below figure.


Since drop-down lists are a common feature on most website, employ the Select class in Selenium is rather useful when it comes to testing that option in website. This article aims to take users through the process and help them thoroughly test websites to ensure optimum user experience in all possible aspects.

Talk to an Expert

Test Selenium Dropdowns on Real Browsers with BrowserStack Automate

When you write Selenium handwriting for dropdowns using the Select class, they may work locally but behave otherwise on early browser or operating systems—especially when obscure sheathing, timing topic, or browser quirks are involved.

BrowserStack Automate helps you catch these inconsistencies early by running your Selenium tests on existent background browsers and nomadic devices.

  • Real browser and devices:Execute exam on 1000 of real device and browsers, covering different versions and OS combinations so you can validate Select stratum behavior in real-world environments.
  • execution:Run hundred of tests simultaneously to greatly reduce overall executing time—especially useful when your suite has many dropdown-related suit across different platforms.
  • Seamless consolidation:Integrate your existing Selenium examination with democratic CI/CD tools like, GitHub Actions, and for full automated regression and release pipelines.
  • Secure local examination:Test applications that are host behind firewalls or in growth environs, so you can validate dropdowns yet before deploying to staging or product.
  • Rich reporting and debugging tools:Access video transcription, screenshots, logs, and network touch for every test run. These insights facilitate you see incisively how dropdowns be interacted with on remote browsers and trace failures back to their beginning cause speedily.

Using BrowserStack Automate alongside Selenium assure your Quality family interactions aren ’ t just surpass locally—but are truly cross-browser compatible and reliable in.

Conclusion

The Select category in Selenium volunteer a unseamed way to cover dropdown elements via method like selectByIndex (), selectByVisibleText (), getFirstSelectedOption (), etc. It makes interaction with both single-select and multi-select dropdowns much easier. This makes form automation more efficient and reliable. Furthermore, you can use tools like BrowserStack to scale and streamline your Selenium tests and access wide variety of test environments.

Useful Resources for Selenium

Methods, Classes, and Commands

Configuration

XPath

Locators and Selectors

Waits in Selenium

Frameworks in Selenium

Miscellaneous

Best Practices, Tips and Tricks

Design Patterns in Selenium: Page Object Model and Page Factory

Action Class

TestNG and Selenium

JUnit and Selenium

Use Cases

Types of Testing with Selenium

Tags

FAQs

Use the Select class only when the dropdown is apply using a native HTML & lt; select & gt; tag. It does not act with tradition or JavaScript-based dropdowns.

Dropdown examination can betray due to browser-specific rendering, clock topic, or hidden overlayer. Running tryout on real browsers helps identify these environment-specific issues betimes.

Yes. If the dropdown supports multiple option, the Select class provides method like isMultiple (), selectByVisibleText (), and deselectAll () to manage multiple options effectively.

36,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