Multi-Select Dropdown

Introduction

A Multi-Select Dropdown is a special type of dropdown that allows users to select multiple options simultaneously. Unlike regular Select Dropdowns, where only one option can be selected at a time, Multi-Select Dropdowns support selecting two or more values based on the application’s requirements.

In Selenium, Multi-Select Dropdowns are handled using the Select class. Selenium provides useful methods such as is_multiple, select_by_visible_text(), all_selected_options, and deselect_all() to work efficiently with multi-select elements.

In this tutorial, you’ll learn how to handle Multi-Select Dropdowns using Selenium with Python, along with practical examples, real-world scenarios, common mistakes, and best practices.


What is a Multi-Select Dropdown?

A Multi-Select Dropdown is an HTML <select> element that allows users to select multiple options simultaneously.

Common examples include:

  • Selecting Multiple States

  • Selecting User Roles

  • Choosing Multiple Skills

  • Product Category Selection

  • Language Preferences

  • Report Filters

Example HTML:

<select multiple>
    <option>Florida</option>
    <option>Ohio</option>
    <option>Texas</option>
</select>

The multiple attribute allows users to select more than one option from the dropdown.


Why Automate Multi-Select Dropdowns?

Automating Multi-Select Dropdowns helps you:

  • Validate multiple user selections.

  • Perform data-driven testing.

  • Verify application workflows.

  • Improve automation coverage.

  • Reduce manual testing effort.


Common Methods Used

MethodPurpose
is_multipleVerifies whether multiple selections are allowed
select_by_visible_text()Selects an option using its displayed text
select_by_value()Selects an option using its value attribute
select_by_index()Selects an option using its index
all_selected_optionsRetrieves all selected options
first_selected_optionRetrieves the first selected option
deselect_all()Removes all selected options
deselect_by_visible_text()Removes a selected option

Example

The following example selects multiple options from a Multi-Select Dropdown and verifies that the selected values are present.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select


# Topic: 26. Dropdown Handling - Multi-Select Dropdown
# Practice site: https://www.testmuai.com/selenium-playground/select-dropdown-demo
# Run: pytest -s 26_examples/test_02_multi_select_dropdown.py
#
# Multi-select dropdowns allow selecting multiple options. Use is_multiple to
# check and select_by_index or select_by_visible_text for each option.


def test_multi_select_dropdown():
    driver = webdriver.Chrome()

    try:
        driver.get("https://www.testmuai.com/selenium-playground/select-dropdown-demo")

        multi_select = Select(driver.find_element(By.ID, "multi-select"))

        if multi_select.is_multiple:
            multi_select.select_by_visible_text("Florida")
            multi_select.select_by_visible_text("Ohio")

            selected_texts = [
                option.text
                for option in multi_select.all_selected_options
            ]

            assert "Florida" in selected_texts
            assert "Ohio" in selected_texts
        else:
            multi_select.select_by_visible_text("Florida")
            assert (
                multi_select.first_selected_option.text
                == "Florida"
            )
    finally:
        driver.quit()

Output

Florida
Ohio

Both options are selected successfully, and Selenium verifies that they are present in the list of selected options.


Understanding the Code

Import the Required Classes

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

Imports:

  • webdriver for launching and controlling the browser.

  • By for locating web elements.

  • Select for handling Select and Multi-Select Dropdowns.

Create the WebDriver

driver = webdriver.Chrome()

Launches a new Chrome browser session.

Open the Practice Website

driver.get(
    "https://www.testmuai.com/selenium-playground/select-dropdown-demo"
)

Opens the practice webpage containing the Multi-Select Dropdown.

Locate the Multi-Select Dropdown

multi_select = Select(
    driver.find_element(
        By.ID,
        "multi-select"
    )
)

Selenium first locates the dropdown element and then wraps it using the Select class.

Verify Whether Multiple Selection is Allowed

if multi_select.is_multiple:

The is_multiple property verifies whether the dropdown supports selecting multiple options.

Output:

True

If the dropdown allows multiple selections, Selenium proceeds with selecting multiple values.

Select Multiple Options

multi_select.select_by_visible_text("Florida")

multi_select.select_by_visible_text("Ohio")

The select_by_visible_text() method selects options based on their displayed text.

Multiple options can be selected one after another if the dropdown supports multiple selections.

Retrieve All Selected Options

selected_texts = [
    option.text
    for option in multi_select.all_selected_options
]

The all_selected_options property returns a list containing all currently selected options.

This is particularly useful when validating multiple selections.

Verify the Selected Options

assert "Florida" in selected_texts

assert "Ohio" in selected_texts

These assertions verify that both options were successfully selected.

Handle Single-Select Dropdowns

else:
    multi_select.select_by_visible_text("Florida")

    assert (
        multi_select.first_selected_option.text
        == "Florida"
    )

If the dropdown does not support multiple selections, Selenium selects a single option and verifies it using:

first_selected_option

This makes the script more robust and reusable across different types of dropdowns.

Close the Browser

driver.quit()

Closes the browser and ends the WebDriver session.

This is a recommended practice to ensure that all browser instances are properly terminated after test execution.


Retrieving All Selected Options

You can retrieve every selected option using:

selected_options = (
    multi_select.all_selected_options
)

Example:

for option in selected_options:
    print(option.text)

Output:

Florida
Ohio

This is useful when validating multiple user selections.


Removing Selected Options

You can deselect options using:

multi_select.deselect_by_visible_text(
    "Florida"
)

To remove all selected options:

multi_select.deselect_all()

Note: deselect_all() works only with Multi-Select Dropdowns.


Practical Example

Suppose an e-commerce website allows users to select multiple product categories.

The automation script:

  • Selects Electronics.

  • Selects Home Appliances.

  • Selects Accessories.

  • Verifies that only the relevant products are displayed.

This validates both the dropdown functionality and the application’s business workflow.


Automation Testing Example

Consider an HR Management application.

The employee registration page allows administrators to assign multiple skills such as:

  • Python

  • Selenium

  • SQL

  • API Testing

The automation script:

  • Selects multiple skills.

  • Submits the registration form.

  • Verifies that all selected skills are stored successfully.

Multi-Select Dropdowns are frequently used in enterprise applications that support multiple user selections.


Real-World Example

Multi-Select Dropdowns are commonly used in:

  • Banking applications

  • E-commerce websites

  • CRM systems

  • Healthcare portals

  • HR management systems

  • Government websites

  • Enterprise web applications

They are particularly useful whenever users must select multiple values simultaneously.


Advantages of Automating Multi-Select Dropdowns

  • Supports multiple user selections.

  • Improves automation coverage.

  • Supports data-driven testing.

  • Validates business workflows.

  • Reduces manual testing effort.


Common Mistakes Beginners Make

Forgetting to Verify is_multiple

Always verify whether the dropdown supports multiple selections.

Example:

multi_select.is_multiple

Attempting to deselect options from a single-select dropdown will cause Selenium to raise an exception.

Using Incorrect Locators

Always prefer stable locators such as:

  • ID

  • Name

  • CSS Selector

Avoid fragile XPath expressions whenever possible.

Forgetting to Validate Selected Options

Always verify the selected values using:

all_selected_options

This ensures that Selenium selected the correct options successfully.

Ignoring Synchronization

Some dropdowns load dynamically after API calls.

Use Explicit Wait whenever necessary before interacting with them.


Best Practices

  • Always verify is_multiple before selecting multiple options.

  • Prefer select_by_visible_text() whenever possible.

  • Use all_selected_options for validating selections.

  • Use stable locators such as ID and Name.

  • Use Explicit Wait for dynamically loaded dropdowns.

  • Validate selected values after every selection.


Conclusion

Multi-Select Dropdowns allow users to select multiple options simultaneously and are widely used across modern web applications. Selenium’s Select class provides powerful methods such as is_multiple, select_by_visible_text(), and all_selected_options for handling these elements efficiently. Following best practices such as validating selections and using stable locators helps create robust and maintainable Selenium automation scripts.


Frequently Asked Questions (FAQs)

Which class is used to handle Multi-Select Dropdowns?

Use:

Select()

from:

selenium.webdriver.support.ui

How can I verify whether a dropdown supports multiple selections?

Use:

multi_select.is_multiple

How can I retrieve all selected options?

Use:

multi_select.all_selected_options

Can I remove all selected options?

Yes.

Use:

multi_select.deselect_all()

This method works only for Multi-Select Dropdowns.

Are Multi-Select Dropdowns commonly automated in Selenium?

Yes.

They are widely used in filters, registration forms, HR systems, and enterprise web applications that support multiple selections.


Key Takeaways

  • Multi-Select Dropdowns allow users to select multiple values simultaneously.

  • Selenium uses the Select class to handle them efficiently.

  • Use is_multiple to verify whether multiple selections are supported.

  • Use select_by_visible_text() to select options.

  • Use all_selected_options to validate selected values.

  • Use deselect_all() to remove all selections when required.

  • Proper synchronization and validation improve automation reliability.