How to Handle Dropdowns in Selenium: Select Class Methods + Easier Katalon Approach

how to handle dropdown in selenium technical guide

How to handle dropdowns in Selenium with the Select class, using selectByIndex, selectByVisibleText, selectByValue and deselectAll, plus a faster way to do the same in Katalon Studio with Spy Web and built-in keywords.

Key takeaways
The 30-second version of this article
A dropdown is an HTML <select> element that shows one value until clicked, then lists all its options.
Selenium's Select class wraps a located <select> element so you can choose options with selectByIndex, selectByVisibleText or selectByValue.
deselectAll clears every selected option, but only works on dropdowns that allow multiple selections.
In Katalon Studio, you capture the dropdown with Spy Web, then use keywords such as WebUI.selectOptionByValue or WebUI.selectOptionByIndex without writing Select boilerplate.

In this article, we’ll quickly cover the core Selenium commands for dropdowns and then show how Katalon Studio streamlines the same process - letting you capture a dropdown with Spy Web and select options using built-in keywords like selectOptionByValue or selectOptionByIndex, so you can automate dropdown interactions without writing boilerplate code, but first...

What is dropdown in Selenium?

In a web application, a dropdown menu (also called a dropdown list) is a graphical control element that lets users pick one option from a list. When inactive, it shows a single selected value. When clicked, it expands to display all available options. A dropdown is presented as follows in HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Select Element Example</title>
  </head>
  <body>
    <h1>The select element</h1>
    <p>The select element is used to create a drop-down list.</p>

    <form action="/action_page.php">
      <label for="cars">Choose a car:</label>
      <select name="cars" id="cars">
        <option value="volvo">Volvo</option>
        <option value="saab">Saab</option>
        <option value="opel">Opel</option>
        <option value="audi">Audi</option>
      </select>
      <br /><br />
      <input type="submit" value="Submit" />
    </form>

    <p>
      Click the "Submit" button and the form-data will be sent to a page on
      the server called "action_page.php".
    </p>
  </body>
</html>

What is Select class in Selenium?

The Select class provides convenient methods to interact with <select> HTML elements. You must first locate the dropdown element, then use Select to select or deselect items. 

Common <select> class methods

1. selectByIndex()

Select the option at the given index. the Index starts from `0`.

Example Java code:

Select dropdown = new Select(driver.findElement(By.id("cars"))); 
dropdown.selectByIndex(2);

What it does: This code selects the option at index 2, which corresponds to the third option in the list.

2. selectByVisibleText()

Select all options that display text matching the argument.

Example Java code:

Select dropdown = new Select(driver.findElement(By.id("cars")));
dropdown.selectByVisibleText("Audi");

What it does: The code finds the dropdown by its ID, wraps it with the `Select` class, and selects the option with displayed text matching "Audi".

3. selectByValue()

Select all options that have a value matching the argument.

Example Java code:

Select dropdown = new Select(driver.findElement(By.id("cars")));
dropdown.selectByValue("saab");

What it does: The code selects the option with value attribute as "saab".

4. deselectAll()

Clear all selected items. Note that this method only works on a multi-select dropdown.

Example Java code:

// Only works when the <select> element has the multiple attribute
Select dropdown = new Select(driver.findElement(By.id("cars")));
dropdown.deselectAll();

Handle dropdown with Katalon Studio

Katalon Studio provides built-in keywords for the Select class that simplify dropdown handling and automate your testing workflow. 

Let’s give it a try! First we’ll need to capture some objects that we can use in the test case.

📄 Learn more in our documentation: How to handle dropdown menu in Katalon Studio

Capture objects with Spy Web

Step 1. In your test project, open the Spy Web tool.

Screenshot 2025-05-19 at 14.03.48


Step 2. Provide a link in the URL field. Here we’re using the https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select site that contains a drop-down list.

Step 3. Click Start to launch your session. Navigate your cursor to the dropdown and right-click > Capture Object.

How to capture drop down object on a web page using Katalon Studio

The object we captured is a <select> HTML element, and its XPath attributes are displayed in the Object Spy dialog. 

Capturing a <select> HTML element by its XPath in Katalon Studio

Click Save > OK in the Add Element to Object Repository dialog.
How to add captured Element to the Object Repository in Katalon Studio


Use Katalon built-in keywords

With the objects you have captured, you can start creating test steps with Katalon Studio built-in keywords.

Open your test case in the Manual view, create a test case using the WebUI.selectOptionByValue keyword that finds the value="saab”

Using Katalon built-in keywords


You can test it out with this script:

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.openBrowser('')
WebUI.navigateToUrl('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select')

// The third argument (isRegex) is false: match the value exactly
WebUI.selectOptionByValue(findTestObject('Object Repository/Page_W3Schools/select_Cars'), 'saab', false)
WebUI.verifyOptionSelectedByValue(findTestObject('Object Repository/Page_W3Schools/select_Cars'), 'saab', false, 10)

WebUI.closeBrowser()

If you want to use another keyword, for example WebUI.selectOptionByIndex, try:

import com.kms.katalon.core.model.FailureHandling

WebUI.selectOptionByIndex(findTestObject('Object Repository/Page_W3Schools/select_Cars'), 2, FailureHandling.STOP_ON_FAILURE)

Conclusion

Handling dropdowns is straightforward with Selenium’s Select class - just locate the <select> element and call methods like selectByIndex, selectByVisibleText, or selectByValue - but maintaining those scripts can become tedious over time. Katalon Studio streamlines the same workflow by letting you capture the dropdown with Spy Web and then call keywords like selectOptionByValue or selectOptionByIndex without writing extra boilerplate. Whether you prefer full control through Selenium code or a faster, low-code approach in Katalon, both paths ensure your dropdown interactions stay reliable and easy to maintain.

upgrade-from-selenium-to-katalon-studio

Frequently asked questions

Trinh Huynh
Trinh HuynhTechnical Writer, Katalon

Trinh Huynh is an experienced technical writer in the software testing industry. She blends her extensive technical knowledge with deep understanding of the Katalon products to create guides that help testers of all levels.

Connect on LinkedIn →
Get started

Test everything. Ship with confidence.

From generating test cases to spotting failures, Katalon's AI works across your entire pipeline, automatically.

Live webinar

The Next Evolution of Manual Testing: Introducing Katalon AI Test Runner

Learn how to grow your QA team's capacity in the age of AI, then watch Katalon AI Test Runner turn manual test cases into automated runs, live.

2:00 to 3:00 PM IST
Almas AhmedSenior Account Manager
Sumit WankhedeSolutions Engineer Manager
Register now