App & Browser Testing Made Easy

Give your users a seamless experience by testing on 3000+ real devices and browsers. Don't compromise with emulators and simulators

Home Guide Select Class in Selenium : How to select a value in dropdown list?

Select Class in Selenium : How to select a value in dropdown list?

By Neha Vaidya, Community Contributor -

Table of Contents

A webpage consists of multiple elements such as text fields, buttons, menus, drop-down options. As every tester is aware, Selenium is the most widely used tool for end-to-end automation testing of a website. This article discusses how Selenium is used to find web elements in a drop-down menu on a website.

The article covers the following topics:

  • Introduction to Select Class in Selenium
  • Different Select Methods
  • Selecting Multiple items with select command
  • Demo: Illustrating the use of Select class in Selenium

Introduction to Select Class in Selenium

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


Select objSelect = new Select();

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

Different Select Methods

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

1. selectByVisibleText: selectByVisibleText(String arg0): void

This method is used to select one of the options in a drop-down box or an option among multiple selection boxes. It takes a parameter of String which is one of the values of Select element and it returns nothing.




Select objSelect =new Select(driver.findElement("search-box")));

2. selectByIndex: selectByIndex(int arg0) : void

This method is similar to ‘selectByVisibleText’, but the difference here is that the user has to provide the index number for the option rather than text. It takes the integer parameter which is the index value of Select element and it returns nothing.




Select objSelect = new Select(driver.findElement("Seacrch-box")));

3. selectByValue: selectByValue(String arg0) : void

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




Select objSelect = new Select(driver.findElement("Search-box")));
objSelect.selectByValue("Automation Testing");

4. getOptions: getOptions( ) : List<WebElement>

This method gets all the options belonging to the Select tag. It takes no parameter and returns List<WebElements>.




Select objSelect = new Select(driver.findElement("Search-box")));
List <WebElement> elementCount = oSelect.getOptions();

5. deselectAll()

This method clears all the selected entries. This is only valid when the drop-down element supports multiple selections.



Now let’s delve deeper to understand how to select multiple items with the Select command.

Try Selenium Testing on Real Device Cloud for Free

How to select multiple items with the Select command?

The multiple select attribute is a boolean expression. This method specifies that multiple options can be selected at once. These options vary for different operating systems and browsers.

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

Use the isMultiple method to select multiple commands.

isMultiple(): boolean – This method informs whether the Select element supports multiple selection options at the same time or not. This method accepts nothing and returns a boolean value (true/false).




Select objSelect = new Select(driver.findElement(;
// Or can be used as
// Or can be used as

Now let’s look at a real-time example of the select command.

Illustrating the use of Select class in Selenium

In this example, let’s explore how to select a value in a drop-down list 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;
import org.openqa.selenium.WebElement;

public class SelectExample {
public static void main(String[] args) throws InterruptedException {
System.setProperty("", "Path_of_Chrome_Driver");
WebDriver driver = new ChromeDriver();
WebElement developers_dropdown = driver.findElement("developers-menu-toggle"));
Select objSelect = new Select(developers_dropdown);
WebElement solutions_dropdown = driver.findElement("solutions-menu-dropdown"));
Select solutions = new Select(solutions_dropdown);
WebElement solutions_d = driver.findElement("solutions-menu-dropdown"));
Select s1 = new Select(solutions_d();
s1.selectByVisibleText("Geolocation Testing"); 

The code above will direct Selenium to navigate to the Browserstack home page and select the values from the drop-down lists available on the Developers and Solutions tabs as shown in the below figure.

Try Testing Code on BrowserStack Automate for Free

Select class in selenium


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

Automation Testing Selenium Selenium Webdriver

Featured Articles

How to handle Cookies in Selenium WebDriver

How to get HTML source of a Web Element in Selenium WebDriver

Curated for all your Testing Needs

Actionable Insights, Tips, & Tutorials delivered in your Inbox
By subscribing , you agree to our Privacy Policy.
thank you illustration

Thank you for Subscribing!

Expect a curated list of guides shortly.