---
description: Following is a step by step process on how to select value from dropdown in Selenium
title: How to Select Value from Dropdown in Selenium
image: https://www.guru99.com/images/select-option-dropdown-selenium-webdriver.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

Select Value from Dropdown in Selenium uses the dedicated Select class to control HTML SELECT elements. The class exposes selectByVisibleText, selectByValue, and selectByIndex methods that pick options precisely and support multi-select drop-downs.

* 📦 **Import the package:** Bring in org.openqa.selenium.support.ui.Select and wrap the WebElement before calling any selection method.
* 🎯 **Pick the right method:** Choose selectByVisibleText, selectByValue, or selectByIndex based on whether display text, value attribute, or position is most stable.
* 🔁 **Handle multi-select drop-downs:** Use isMultiple to detect them, and deselectAll or deselectByVisibleText to clear previous choices.
* ✅ **Verify the selection:** Call getFirstSelectedOption to confirm the test actually changed the drop-down state.
* 🤖 **Use AI locators:** Self-healing AI locators repair broken select-element XPaths after UI changes, keeping drop-down tests stable across releases.

[ Read More ](javascript:void%280%29;) 

![Select Value from Dropdown in Selenium](https://www.guru99.com/images/select-option-dropdown-selenium-webdriver.png)

## What is the Select Class in Selenium?

The **Select class in Selenium** is a helper class from the `org.openqa.selenium.support.ui` package that lets WebDriver interact with HTML `<select>` elements. It exposes methods to select and deselect options by visible text, value, or index, and to detect whether a drop-down accepts multiple selections.

Because `Select` is a regular Java class, you create an instance with the `new` keyword and pass the WebElement that points to the `<select>` tag on the page.

## How to Select Dropdown in Selenium

Before handling a drop-down in Selenium, two steps are required:

1. Import the package **org.openqa.selenium.support.ui.Select**.
2. Instantiate the drop-down as a `Select` object in Selenium WebDriver.

As an example, open the Mercury Tours’ Registration page (<https://demo.guru99.com/test/newtours/register.php>) and locate the “Country” drop-down.

[](https://www.guru99.com/images/image011%283%29.png)

**Step 1) Import the Select package.**

```
import org.openqa.selenium.support.ui.Select;
```

**Step 2) Declare the drop-down element as an instance of the Select class.** In the example below, the instance is named `drpCountry`.

```
Select drpCountry = new Select(driver.findElement(By.name("country")));
```

**Step 3) Start controlling the drop-down.** Use any Select method to pick an option. The sample below selects “ANTARCTICA”:

```
drpCountry.selectByVisibleText("ANTARCTICA");
```

## Select Methods in Selenium

The Select class provides several methods to interact with drop-down options. The five most common are described below.

### 1) selectByVisibleText() and deselectByVisibleText()

* Selects or deselects the option whose displayed text matches the parameter.
* **Parameter:** the exact text displayed for the option.

**Example:**

```
drpCountry.selectByVisibleText("ANTARCTICA");
```

### 2) selectByValue() and deselectByValue()

* Selects or deselects the option whose `value` attribute matches the parameter.
* Note that the displayed text and the `value` attribute are often different, as shown below.
* **Parameter:** the option’s `value` attribute.

[](https://www.guru99.com/images/image019%282%29.png)

**Example:**

```
drpCountry.selectByValue("234");
```

### RELATED ARTICLES

* [What is Selenium? Introduction Tutorial ](https://www.guru99.com/introduction-to-selenium.html "What is Selenium? Introduction Tutorial")
* [AutoIT in Selenium Tutorial: How to use it? ](https://www.guru99.com/use-autoit-selenium.html "AutoIT in Selenium Tutorial: How to use it?")
* [How to Execute Failed Test Cases in TestNG ](https://www.guru99.com/run-failed-test-cases-in-testng.html "How to Execute Failed Test Cases in TestNG")
* [How to Take Screenshot in Selenium WebDriver ](https://www.guru99.com/take-screenshot-selenium-webdriver.html "How to Take Screenshot in Selenium WebDriver")

### 3) selectByIndex() and deselectByIndex()

* Selects or deselects the option at the given index. Indexes are zero-based.
* **Parameter:** the integer index of the option.

**Example:**

```
drpCountry.selectByIndex(0);
```

### 4) isMultiple()

* Returns `TRUE` if the drop-down allows multiple selections at the same time, otherwise `FALSE`.
* **Parameter:** none.

**Example:**

```
if (drpCountry.isMultiple()) {
    // do something here
}
```

### 5) deselectAll()

* Clears every selected option. Only valid on multi-select drop-downs.
* **Parameter:** none.

**Example:**

```
drpCountry.deselectAll();
```

## Complete Code of Select Methods in Selenium

The following Java program demonstrates the Select class on both a single-select and a multi-select drop-down.

```
package newpackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.By;

public class accessDropDown {
    public static void main(String[] args) {
        System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
        String baseURL = "https://demo.guru99.com/test/newtours/register.php";
        WebDriver driver = new FirefoxDriver();
        driver.get(baseURL);

        // Single-select drop-down
        Select drpCountry = new Select(driver.findElement(By.name("country")));
        drpCountry.selectByVisibleText("ANTARCTICA");

        // Multi-select drop-down
        driver.get("http://jsbin.com/osebed/2");
        Select fruits = new Select(driver.findElement(By.id("fruits")));
        fruits.selectByVisibleText("Banana");
        fruits.selectByIndex(1);
    }
}
```

## Selecting Items in a Multiple SELECT element

The `selectByVisibleText()` method also works on multi-select drop-downs. As an example, use <https://jsbin.com/osebed/2> as the base URL. It exposes a drop-down that accepts multiple selections at once.

[](https://www.guru99.com/images/image015%283%29.png)

The snippet below selects the first two options using `selectByVisibleText()`:

[](https://www.guru99.com/images/image016%283%29.png)

## Method Reference Table

This table summarises every Select-class method covered above for quick lookup.

| Command                                         | Description                                                                |
| ----------------------------------------------- | -------------------------------------------------------------------------- |
| selectByVisibleText() / deselectByVisibleText() | Selects or deselects an option by its displayed text.                      |
| selectByValue() / deselectByValue()             | Selects or deselects an option by its value attribute.                     |
| selectByIndex() / deselectByIndex()             | Selects or deselects an option by its zero-based index.                    |
| isMultiple()                                    | Returns TRUE if the drop-down allows multiple selections, otherwise FALSE. |
| deselectAll()                                   | Deselects all previously selected options on a multi-select drop-down.     |

To control drop-down boxes, import the `org.openqa.selenium.support.ui.Select` package first, then create a Select instance and call any of the methods above.

## FAQs

⚡ What is the Select class in Selenium WebDriver?

The Select class is a Selenium helper for HTML SELECT elements. It wraps a WebElement and exposes selectByVisibleText, selectByValue, selectByIndex, isMultiple, and deselectAll for clean drop-down automation.

🚀 Which Select method should I prefer in stable tests?

Prefer selectByValue when the value attribute is stable, because labels often change for localization. Use selectByVisibleText when the text is authoritative, and avoid selectByIndex when option order may change.

💡 Why does Select throw UnexpectedTagNameException?

The Select class only works on real HTML SELECT tags. If the WebElement is a div, ul, or custom widget styled to look like a drop-down, you must click options through WebElement.click() or the Actions API instead.

🔒 How can I verify that an option was actually selected?

Call getFirstSelectedOption() on the Select instance and assert its getText() value. For multi-select drop-downs, iterate getAllSelectedOptions() and compare the returned list with the expected selections.

📐 Can the Select class handle multi-select drop-downs?

Yes. Use isMultiple() to confirm the drop-down allows multiple values, then call selectByVisibleText multiple times or deselectAll() to reset. Multi-select drop-downs require the HTML SELECT element to declare the multiple attribute.

⏱️ How do I wait for drop-down options to load before selecting?

Use WebDriverWait with ExpectedConditions.numberOfElementsToBeMoreThan on the option locator. This ensures async-populated drop-downs are ready before instantiating the Select class and calling any selection method.

🤖 How can AI help maintain Selenium drop-down tests?

AI-powered self-healing locators detect when a SELECT element’s id, name, or XPath has changed and switch to a working alternative. They reduce flaky drop-down failures in pipelines after UI redesigns.

✍️ Can AI generate Select-class code for a given drop-down?

Yes. AI coding assistants turn a plain-English request such as “select country ANTARCTICA on the register page” into a complete Select instance with the right locator, selectByVisibleText call, and a verification assertion.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/select-option-dropdown-selenium-webdriver.png","url":"https://www.guru99.com/images/select-option-dropdown-selenium-webdriver.png","width":"600","height":"250","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/select-option-dropdown-selenium-webdriver.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/selenium","name":"Selenium"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/select-option-dropdown-selenium-webdriver.html","name":"How to Select Value from Dropdown in Selenium"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/select-option-dropdown-selenium-webdriver.html#webpage","url":"https://www.guru99.com/select-option-dropdown-selenium-webdriver.html","name":"How to Select Value from Dropdown in Selenium","dateModified":"2026-05-27T15:54:25+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/select-option-dropdown-selenium-webdriver.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/select-option-dropdown-selenium-webdriver.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/admin","name":"Krishna Rungta","url":"https://www.guru99.com/author/admin","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/krishna-rungta-v2-120x120.png","url":"https://www.guru99.com/images/krishna-rungta-v2-120x120.png","caption":"Krishna Rungta","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Selenium","headline":"How to Select Value from Dropdown in Selenium","description":"Following is a step by step process on how to select value from dropdown in Selenium","keywords":"selenium","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/admin","name":"Krishna Rungta"},"dateModified":"2026-05-27T15:54:25+05:30","image":{"@id":"https://www.guru99.com/images/select-option-dropdown-selenium-webdriver.png"},"copyrightYear":"2026","name":"How to Select Value from Dropdown in Selenium","subjectOf":[{"@type":"HowTo","name":"How to Select Dropdown in Selenium?","description":"Here is a step by step process on How to Handle Dropdown in Selenium:","step":[{"@type":"HowToStep","name":"Step 1) Import the 'Select' package.","text":"import org.openqa.selenium.support.ui.Select;","url":"https://www.guru99.com/select-option-dropdown-selenium-webdriver.html#step1"},{"@type":"HowToStep","name":"Step 2) Declare the drop-down element as an instance of the Select class.","text":"In the example below, we named this instance as 'drpCountry'.","url":"https://www.guru99.com/select-option-dropdown-selenium-webdriver.html#step2"},{"@type":"HowToStep","name":"Step 3) Start Controlling it.","text":"We can now start controlling 'drpCountry' by using any of the available Select methods to select dropdown in Selenium. The sample code below will select the option 'ANTARCTICA.'","url":"https://www.guru99.com/select-option-dropdown-selenium-webdriver.html#step3"}]},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the Select class in Selenium WebDriver?","acceptedAnswer":{"@type":"Answer","text":"The Select class is a Selenium helper for HTML SELECT elements. It wraps a WebElement and exposes selectByVisibleText, selectByValue, selectByIndex, isMultiple, and deselectAll for clean drop-down automation."}},{"@type":"Question","name":"Which Select method should I prefer in stable tests?","acceptedAnswer":{"@type":"Answer","text":"Prefer selectByValue when the value attribute is stable, because labels often change for localization. Use selectByVisibleText when the text is authoritative, and avoid selectByIndex when option order may change."}},{"@type":"Question","name":"Why does Select throw UnexpectedTagNameException?","acceptedAnswer":{"@type":"Answer","text":"The Select class only works on real HTML SELECT tags. If the WebElement is a div, ul, or custom widget styled to look like a drop-down, you must click options through WebElement.click() or the Actions API instead."}},{"@type":"Question","name":"How can I verify that an option was actually selected?","acceptedAnswer":{"@type":"Answer","text":"Call getFirstSelectedOption() on the Select instance and assert its getText() value. For multi-select drop-downs, iterate getAllSelectedOptions() and compare the returned list with the expected selections."}},{"@type":"Question","name":"Can the Select class handle multi-select drop-downs?","acceptedAnswer":{"@type":"Answer","text":"Yes. Use isMultiple() to confirm the drop-down allows multiple values, then call selectByVisibleText multiple times or deselectAll() to reset. Multi-select drop-downs require the HTML SELECT element to declare the multiple attribute."}},{"@type":"Question","name":"How do I wait for drop-down options to load before selecting?","acceptedAnswer":{"@type":"Answer","text":"Use WebDriverWait with ExpectedConditions.numberOfElementsToBeMoreThan on the option locator. This ensures async-populated drop-downs are ready before instantiating the Select class and calling any selection method."}},{"@type":"Question","name":"How can AI help maintain Selenium drop-down tests?","acceptedAnswer":{"@type":"Answer","text":"AI-powered self-healing locators detect when a SELECT element's id, name, or XPath has changed and switch to a working alternative. They reduce flaky drop-down failures in pipelines after UI redesigns."}},{"@type":"Question","name":"Can AI generate Select-class code for a given drop-down?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI coding assistants turn a plain-English request such as \"select country ANTARCTICA on the register page\" into a complete Select instance with the right locator, selectByVisibleText call, and a verification assertion."}}]}],"@id":"https://www.guru99.com/select-option-dropdown-selenium-webdriver.html#schema-244474","isPartOf":{"@id":"https://www.guru99.com/select-option-dropdown-selenium-webdriver.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/select-option-dropdown-selenium-webdriver.html#webpage"}}]}
```
