Contents

    Guides

    Dropdown in Selenium (A Complete Guide for 2026)

    Published on

    October 24, 2025
    Dropdown in Selenium (A Complete Guide for 2026)

    The primary reason why developers struggle to test dropdowns is because automation scripts execute faster, while dynamic UI is slower to respond. 

    If a user clicks on the “country” dropdown, the UI in the front end might not have rendered the “state” list; that will trigger a "NoSuchElement" exception in Selenium. Handling dropdowns in Selenium helps match the asynchronous timing of UI, locate dynamic HTML components, and align with the right DOM tree. 

    Selenium WebDriver provides multiple approaches for interacting with dropdowns, ranging from standard HTML <Select> elements to dynamically generated custom dropdowns.

    Run Selenium Tests on Cloud

    Why Should You Handle DropDown in Selenium?

    Dropdowns do not fall because your logic is wrong; they fall because the page changes faster than most test scripts can catch up with. Elements underneath keep shifting, and the server gets updated every time it shifts. Which displaces the component. 

    Dropdowns are rarely broken by the test logic itself; they break because the page changes state faster than most scripts account for.

    1. The "Element Stale / Not Found" Race Condition

    In modern frameworks (Angular, VUE), HTML ID and the underlying document object model (DOM) are displaced if the site is refreshed. 

    A locator that still points to the older ID may no longer be a match and will throw a “NoSuchElement” exception. Or the UI component detected at t+0, before the file got destroyed and reloaded at t+1, won’t be detected again by the test click at t+2. It will throw a “StaleElementReference” exception.

    It is important to rely on Selenium WebDriver to identify HTML, interact with the DOM, and cross-test an element at the same time it’s rendered to test your dropdown.

    2. The "Wrong Tag" Structure Mismatch

    If your script used a <SelectbyValue> method but the dropdown was built with <div><li> or a JavaScript executor like MUI or Ant Design, then your dropdown test would show an exception of "UnexpectedTagName."

    Wrapping up your dropdown in <select> the class of Selenium won’t work for dynamic elements that are custom implemented using different HTML or AJAX structures.

    3. The "Not Yet Interactable" Timing Gap

    Automated test scripts execute in milliseconds, while pages are rendered in seconds, as page rendering depends on API requests, loading the feature, and network consistency. 

    If a test script is executed and lands on the web application page before the element is rendered and interactable, it will give an “ElementNotInteractable Exception.

    Handling dropdowns in Selenium helps you trigger features like explicit wait or thread. sleep() to bridge the gap between async page rendering and testing. 

    4. The Manual-to-Automated Speed Gap

    82% of testers still rely on manual testing day-to-day, where a human naturally waits for the page to catch up. Live testers know when to click, when to verify, and when to test. 

    But in Selenium test automation, the scripts execute, debug, and compile CI/CD fast. There is no built-in “wait until the page is ready” behavior (unless you specifically put a “WebDriverWait”). Sudden bugs, stale elements, and wrong tags are much more likely to trip up your automation and keep on reappearing. 

    You can handle a navigation dropdown by establishing a direct correlation between defined elements. It’s position or sub-menu locations in Selenium. But for that, you should be aware of how the single-page application is structured in the backend, i.e., HTML, select, div, or custom JS.

    How to Handle DropDown in Selenium 

    Handling a dropdown starts with what part of your single-page app or multi-page app you’re currently testing. 

    If your menu was built using <Select> attributes, you can test it via Selenium’s Select class: SelectByVisibleText(), SelectByValue(), or SelectByIndex() for end user validation. 

    Testing modern frameworks with custom dropdowns or React JS needs a different approach. These elements are wrapped up inside JS in a complex way, so it’s hard to test them. Click the trigger element to open it, then locate and click the matching option directly, since the “Select” class doesn’t recognize it. 

    Either way, timing is where most dropdown tests usually fail. 

    A locator that might have worked in identifying dropdowns previously might not continue to work if the ID in the root file has changed. If the element were removed, the DOM reference would have also. While Selenium has other ways to handle dropdown testing, it still displays an old “detached reference," known as the “StaleElementReference Exception. 

    The test fails because the page re-rendered mid-interaction; the DOM tree Selenium had indexed no longer existed, and the element reference pointed to nothing."

    ‍Read More: How to Use Cypress Select for Dropdown Testing

    Example of Dropdown Handling and Failures

    Take a filtering flow on an automobile listing website. Selecting “Cars” under Vehicle Type populates the “fuel type” dropdown, and selecting “Petrol” there triggers an API call that triggers the “mileage” node. 

    The mileage dropdown consists of options like 15-20 kmpl, 20-25 kmpl, and 25+ kmpl, which in turns feeds into a “price” range.

    If your test script tries to select “20-25” kmpl before the previous API call resolves and the dropdown repopulates, it throws a "NoSuchElementException." That option simply doesn’t exist in the DOM yet, even though your locator was working accurately.

    Each selection in the chain depends on an API response. If you skip the wait for any one step, the test fails one level further down.

    Testers can implement threads. sleep() or an explicit wait to fix these inconsistencies and hold testing until the page is rendered. 

    While selecting a dropdown variable, you can either choose the menu class, options, or sub-menu value.

    Read More: How to Use Bird Eats Bug To Debug Your Front-End Application

    Understanding HTML Select Micro-Structure

    Before interacting with a dropdown, it’s important to understand its HTML structure. A typical HTML dropdown looks like this:

    <select id="country">
      <option value="IN">India</option>
      <option value="US">United States</option>
      <option value="UK">United Kingdom</option>
    </select>

    Key attributes:

    • <select> tag represents the dropdown container.
    • <option> Tags represent individual selectable items.
    • Each <option> can have a value and display text.

    Selenium’s Select class is designed specifically to interact with such elements, providing methods to select or deselect options easily.

    For any HTML dropdown consisting of select tags, the <select> class in Selenium is the right way to declare tests. 

    Selenium’s select class is the right tool for the job; it is purpose-built, well-tested, and supports end-to-end automation testing. 

    1. Import and Initialize the Select Class

    The first step is to locate the dropdown WebElement and initialize a Select object.

    import org.openqa.selenium. By
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.support.ui.org.openqa.selenium.support.ui. Select
    
    WebElement dropdown = driver. findElement(By.id("country"));
    Select select = new Select(dropdown);

    2. Selecting Options

    The Select class provides three main methods to select an option:

    / By visible text: matches what the user sees on screen
    select.selectByVisibleText("India");
    
    // By the option's value attribute: matches what gets submitted with the form
    select.selectByValue("IN");
    
    // By position in the list: use with caution
    select.selectByIndex(0); [/prettycode]
    • selectByVisibleText(): targets the option by its display label.
    • selectByValue(): targets the option by its underlying value attribute, which may differ from what the user sees.
    • selectByIndex(): targets by position; breaks silently if the option order changes, so prefer the two methods above wherever the option list isn't fixed.

    3. Retrieving Selected Values

    Select and retrieve your value from the currently selected option:

    // Single-select: get the currently selected option
    WebElement selected = select. getFirstSelectedOption();
    System.out.println(selected.getText());
    
    // Multi-select: get every currently selected option
    List<WebElement> allSelected = select. getAllSelectedOptions();
    for (WebElement option : allSelected) {
        System.out.println(option.getText());

    4. Validating Selected Options

    You can verify which option is currently selected using:

    select.selectByVisibleText("India");
    
    String actual = select. getFirstSelectedOption(). getText();
    Assert.assertEquals(actual, "India", "Dropdown did not select the expected option"); 

    Don't stop at the click; assert against the specific value you expect, not just that something got selected. If you spot a real <select> in HTML, use this class. If not, locate the options manually or through the wait()/thread.sleep() command.

    When Select works:

    • The element is an actual HTML <select> tag
    • Its options are <option> elements

    When Select does not work:

    • Custom dropdowns built using, or <li>
    • JavaScript-rendered components
    • Framework-specific dropdown components (e.g., MUI, Ant Design)

    Handling Custom and Searchable Dropdowns (Without Select)

    Before locating custom dropdowns, map out the anatomy of what you're working with:

    • Dropdown trigger element: The button or field that opens the menu
    • Search input (if available): Present in searchable/autocomplete variants
    • Options container: The element wrapping the full list of choices
    • Individual option elements: Each selectable item
    • Selected value display: Where the chosen value renders back to the user

    Handling Dropdowns Created with <div> and <li>

    <div class="dropdown">
       <button>Select Country</button>
       <ul>
          <li>India</li>
          <li>USA</li>
       </ul>
    </div> 

    Now, click the dropdown trigger, wait for options to render, locate and select the target option, and validate the selected value.

    Handling via Click and FindElement

    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    
    WebElement trigger = driver. findElement(By.tagName("button"));
    wait.until(ExpectedConditions.elementToBeClickable(trigger)).click();
    
    WebElement option = wait.until(ExpectedConditions. visibilityOfElementLocated(
        By.xpath("//ul//li[text()='USA']")));
    option.click();
    
    String selectedText = driver. findElement(By.tagName("button")). getText();
    Assert.assertEquals(selectedText, "USA"); 

    Explicit wait techniques to reach for here:

    • elementToBeClickable: Before clicking the trigger, so you're not clicking a disabled or not-yet-interactive element
    • visibilityOfElementLocated: Before selecting an option, since the list needs to actually render, not just exist
    • presenceOfElementLocated: when you only need the element in the DOM, not necessarily visible yet (useful for elements hidden until scrolled into view)

    After a DOM refresh, you need to relocate the element using a new reference, since the old reference may be invalid and return a StateElementReferenceException.

    Handling Keyword-Based / Searchable Dropdowns

    This covers dropdowns with an embedded search box, type a keyword, the options filter live, and you select from what's left. Common in country selectors, user-search fields, and product autocomplete.

    Click dropdown → Locate search input → Enter keyword → Wait for filtered options → Select matching option → Validate selection

    driver.findElement(By.className("dropdown-toggle")).click();
    
    WebElement searchBox = driver. findElement(By.cssSelector("input.dropdown-search"));
    searchBox.sendKeys("Ind");
    
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    WebElement filteredOption = wait.until(ExpectedConditions. visibilityOfElementLocated(
        By.xpath("//ul[@class='dropdown-menu']//li[text()='India']")));
    filteredOption.click();

    Sendkeys(“Ind”) is your test script that auto-types Ind into the site search box, the same way a user will type out what they want to search.

    It returns the control back to your script instantly, but the page rendering happens slowly (waiting for an API call or a user action). So, if the test executes fast, it can lead to a failure, as “India” isn’t in the DOM the moment your script looks for it.

    Handling JavaScript Framework Dropdowns

    JavaScript includes multiple ways to handle dropdowns based on how they were constructed in the original single page. Developers use React, Angular, or VUE to build SPAs; here, dropdown options always render somewhere else in the DOM and not next to the main element or option.

    There are slightly different Selenium strategies for this:

    React-Based Dropdowns (React Select)

    React renders a hidden form <input> to carry the actual form value, while the form option is dynamically generated later. It uses ARIA technology (elements containing ARIA roles) as an assistive rather than native select option.

    WebElement reactSelect = driver. findElement(By.cssSelector("div.react-select__control"));
    
    // JavaScript Executor fallback: React's synthetic event system doesn't always register a native. click()
    
    
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0]. click();", reactSelect);
    
    WebElement input = driver. findElement(By.cssSelector("input[id^='react-select']"));
    input.sendKeys("Ind");
    
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    WebElement option = wait.until(ExpectedConditions. visibilityOfElementLocated(
        By.cssSelector("div[id$='-option-0']")));
    option.click();

    Because none of this lives in a real <select> tag, getFirstSelectedOption() won't work here either. Calibrate the selection by reading the hidden input's value attribute instead of relying on Selenium's native dropdown API.

    Material UI (MUI) Dropdowns

    MUI's Select, Autocomplete, Menu, and Popover components all render their option list through a portal attached to and expose combobox/listbox/option ARIA roles in place of native tags, with full keyboard navigation built in as the primary interaction model, not just a fallback.

    WebElement combobox = driver. findElement(By.cssSelector("div[role='combobox']"));
    combobox.click();
    
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    List<WebElement> options = wait.until(ExpectedConditions. presenceOfAllElementsLocatedBy(
        By.cssSelector("li[role='option']")));
    
    for (WebElement option : options) {
        if (option.getText().equals("India")) {
            option.click();
            break;
        }
    }
    
    // Keyboard navigation works just as well, since it's MUI's native interaction pattern.
    combobox. sendKeys(Keys.ARROW_DOWN, Keys.ENTER);

    Since the option list is portal-rendered outside the combobox's own DOM subtree, locate it by ARIA role globally, not relative to the trigger element.

    Ant Design Dropdowns

    Ant Design's Select components support search-enabled filtering and dynamic overlays. But what interferes here is virtualization; not all options are currently visible in the DOM even if they might appear on the viewport.

    driver.findElement(By.cssSelector(".ant-select-selector")).click();
    
    WebElement search = driver. findElement(By.cssSelector(".ant-select-selection-search-input"));
    search.sendKeys("Ind");
    
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    WebElement option = wait.until(ExpectedConditions. visibilityOfElementLocated(
        By.xpath("//div[@class='ant-select-item-option-content' and text()='India']")));
    option.click();
    
    // If the target option hasn't rendered yet, scroll the virtualized list container itself.
    WebElement dropdownList = driver. findElement(By.cssSelector(".rc-virtual-list-holder"));
    ((JavascriptExecutor) driver). executeScript("arguments[0]. scrollTop = arguments[0].scrollHeight;", dropdownList); 

    Vue/Angular Component Libraries

    Vue (Vuetify, Element Plus) and Angular (Angular Material, PrimeNG) component libraries run into the same core issues as their React counterparts: dynamically generated attributes, custom non-native DOM structures, keyboard-driven interaction, and virtualized option lists.

    WebElement select = driver. findElement(By.cssSelector("mat-select")); // Angular Material example
    select.click();
    
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    WebElement option = wait.until(ExpectedConditions. visibilityOfElementLocated(
        By.xpath("//mat-option[.//span[text()='India']]")));
    option.click();

    The framework changes, but the root dropdown rendering doesn't. Even with Angular and Vue, you need to identify, wait, and then validate DOM. 

    Working with Multi-Select Dropdowns and Deselect Operations

    Multi-select dropdowns allow users to select multiple options at once. Selenium supports them through the Select class if the HTML element includes the multiple attribute.

    ‍Example

    <select id="skills" multiple>
      <option value="java">Java</option>
      <option value="python">Python</option>
      <option value="selenium">Selenium</option>
    </select> 

    Handling Multi-Select in Selenium

     Select multiSelect = new Select(driver.findElement(By.id("skills")));
    multiSelect.selectByVisibleText("Java");
    multiSelect.selectByVisibleText("Selenium");
    // Deselect one option
    multiSelect.deselectByVisibleText("Java");
    // Retrieve all selected options
    List<WebElement> selectedOptions = multiSelect.getAllSelectedOptions();
    for (WebElement option : selectedOptions) {
        System.out.println(option.getText());
    }

    You can also deselect all selected options at once using deselectAll() when resetting the form.

    Handling Dynamic or Asynchronously-Populated Dropdowns

    Dynamic dropdowns are populated based on user interaction or API responses (e.g., selecting a country populates a “state” dropdown).

    Example Workflow

    1. Select a country from the first dropdown.
    2. Wait for the “state” dropdown to populate.
    3. Select a state dynamically.

    Implementation

    Select country = new Select(driver.findElement(By.id("country")));
    country.selectByVisibleText("India");
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//select[@id='state']/option[text()='Maharashtra']")));
    Select state = new Select(driver.findElement(By.id("state")));
    state.selectByVisibleText("Maharashtra");

    This approach ensures the test waits for data to load before interacting with it, preventing NoSuchElementException.

    Best Practices for Dropdown Handling in Selenium

    Here are some of the best practices for Dropdown Handling in Selenium:

    • Use Explicit Waits: Always wait for dropdown elements or options to load before interacting.
    • Avoid Hardcoded Indexes: Prefer selectByVisibleText() or selectByValue() for reliability.
    • Handle Stale Element Exceptions: Re-locate dropdown elements when the page reloads.
    • Refrain from Fixed Delays: Use dynamic waits instead of Thread.sleep().
    • Encapsulate Dropdown Actions: Create reusable methods for selecting and validating dropdown values to reduce code duplication.

    Troubleshooting Common Dropdown Issues

    Dropdown interactions can fail due to multiple reasons. Below are some common issues and solutions:

    • Element Not Interactable: The dropdown might not be visible; use WebDriverWait or JavaScript Executor to ensure visibility.
    • Incorrect XPath or Locator: Verify that the locator uniquely identifies the dropdown and its options.
    • Overlapping Elements: In cases where overlays block clicks, scroll the element into view using Actions or JavaScript.
    • Timing Issues: Always use waits to handle dynamically loaded dropdowns.

    Scaling Dropdown Tests with Cloud & Real-Device Platforms

    Dropdown bugs are almost never "broken everywhere." They're usually broken on one specific browser or device. A dropdown might work perfectly in Chrome on your laptop but render wrong in Safari or behave differently on a mobile browser. 

    That's exactly why testing on real browsers and devices matters. It's the only way to actually catch these environment-specific failures.

    But once you catch a failure on some device you don't personally have in front of you, a new problem shows up: how do you show your team exactly what went wrong?

    This is where the Bird Eats Bug browser extension helps. Install it in the browser you're testing in, and when a dropdown misbehaves, hit record. It automatically captures the screen recording, console logs, network requests, and system details (browser, OS).

    So instead of writing "the dropdown broke on Safari, I think," you get a report that shows exactly what happened, in exactly that environment, without extra explaining.

    Conclusion

    Handling dropdowns effectively in Selenium is essential for comprehensive automation coverage. Checking for async ARIA assistives, DOM refreshes, and page rendering are essential components that reduce the possibility of flaky tests.

    From standard HTML dropdowns to complex JavaScript-driven ones, Selenium provides multiple methods to interact with them. 

    By leveraging the Select class for standard dropdowns and custom locators or JavaScript for dynamic ones, you can handle a wide variety of dropdowns efficiently. Coupled with tools like BrowserStack Automate, these tests can be executed across real devices and browsers, ensuring your web applications deliver a seamless experience for all users.

    Data-rich bug reports loved by everyone

    Get visual proof, steps to reproduce and technical logs with one click

    Make bug reporting 50% faster and 100% less painful

    Rating LogosStars
    4.6
    |
    Category leader

    Liked the article? Spread the word

    Put your knowledge to practice

    Try Bird on your next bug - you’ll love it

    “Game changer”

    Julie, Head of QA

    star-ratingstar-ratingstar-ratingstar-ratingstar-rating

    Overall rating: 4.7/5

    Try Bird later, from your desktop