How to Handle Dropdown in Playwright – Complete Step-by-Step Guide with Examples (2026)

Introduction: Why Dropdown Automation Is Essential in Modern Web Testing

Dropdowns are one of the most frequently used UI components in modern web applications. Whether users are selecting their country, choosing a payment method, filtering products, selecting a language, or configuring application settings, dropdowns play a crucial role in user interactions.

Testing dropdown functionality manually is repetitive and time-consuming, especially when applications contain dozens of forms and dynamic user interfaces. Automated testing ensures dropdowns behave consistently across browsers and application releases.

If you’re learning how to handle dropdown in Playwright, you’re building an essential automation skill used daily by QA Automation Engineers, SDETs, and software developers.

Playwright simplifies dropdown automation by providing built-in methods like selectOption() for standard HTML dropdowns and flexible locator-based interactions for modern JavaScript dropdown components built with React, Angular, or Vue.

Whether you are:

Learning Playwright dropdown handling will help you automate real-world business workflows more efficiently while writing clean, maintainable automation scripts.

In this guide, you’ll learn:


What Is Dropdown Handling in Playwright?

Dropdown handling in Playwright refers to the process of automatically selecting one or more options from dropdown menus during automated browser testing.

For traditional HTML <select> elements, Playwright provides the selectOption() method. For modern UI frameworks such as React, Angular, and Vue, dropdowns are often custom components that require clicking and selecting options using Playwright locators.

Simple Definition

Dropdown handling in Playwright means selecting options from HTML or custom dropdown controls using Playwright APIs during automated test execution.


Common Automation Use Cases

Dropdown automation is commonly used for:

  • Country selection
  • State and city selection
  • Product category filters
  • Language selection
  • Currency selection
  • User role selection
  • Date and time selection
  • Searchable dropdowns
  • Multi-select controls
  • Enterprise application configuration pages

Benefits of Playwright Dropdown Handling

Using Playwright for dropdown automation provides several advantages:

  • Easy-to-read API
  • Automatic waiting
  • Fast execution
  • Cross-browser compatibility
  • Reliable automation
  • Excellent CI/CD support
  • Better maintainability
  • Reduced flaky tests

Why Automate Dropdown Testing?

Dropdowns are involved in almost every business application. A single registration page may contain multiple dropdowns, while enterprise systems can include hundreds of dropdown components across different workflows.

Automating these interactions helps teams verify application behavior consistently after every deployment.

Benefits for QA Teams

Dropdown automation helps teams:

  • Reduce repetitive manual testing
  • Improve regression coverage
  • Validate user selections
  • Verify dynamic data loading
  • Test multiple browsers
  • Increase automation reliability
  • Accelerate software releases

Real-World Example

Consider an online shopping application.

Customers use dropdowns to select:

  • Product category
  • Brand
  • Color
  • Size
  • Currency
  • Delivery country

Automation verifies that:

  • Correct options appear
  • Selected values are saved
  • Filters work properly
  • Products refresh correctly
  • No invalid options are displayed

Types of Dropdowns in Web Applications

Modern web applications use several kinds of dropdown components.

1. HTML <select> Dropdowns

These are traditional dropdown elements created using the HTML <select> tag.

Example:

<select id=”country”>

    <option value=”us”>USA</option>

    <option value=”in”>India</option>

</select>

These dropdowns are the easiest to automate using selectOption().


2. Custom JavaScript Dropdowns

Modern frameworks like:

  • React
  • Angular
  • Vue

usually replace standard HTML dropdowns with custom UI components.

Instead of <select>, these dropdowns use:

  • <div>
  • <span>
  • <ul>
  • <li>

These require Playwright’s click() and locator() methods.


3. Searchable Dropdowns

Many enterprise applications provide searchable dropdowns.

Examples include:

  • Employee search
  • Country search
  • Customer lookup
  • Product search

Users type text before selecting an option.


4. Multi-Select Dropdowns

Multi-select dropdowns allow users to select multiple values simultaneously.

Examples include:

  • User permissions
  • Skills selection
  • Product tags
  • Categories

Playwright supports multiple selections using an array of values.


5. Dynamic (AJAX) Dropdowns

Dynamic dropdowns load options only after another selection is made.

Example:

Country

     ↓

State

     ↓

City

These require synchronization because data loads asynchronously from the server.


Step-by-Step Guide: How to Handle Dropdown in Playwright

Step 1: Install and Configure Playwright

Create a new Playwright project.

mkdir playwright-dropdown-demo

cd playwright-dropdown-demo

npm init -y

npm init playwright@latest

Verify the installation:

npx playwright test

This ensures Playwright, browser binaries, and the Playwright Test Runner are installed successfully.


Step 2: Select an Option by Visible Text Using selectOption()

import { test } from ‘@playwright/test’;

test(‘Select Country’, async ({ page }) => {

    await page.goto(‘https://example.com’);

    await page.selectOption(‘#country’, {

        label: ‘India’

    });

});

Explanation

This script:

  • Opens the application
  • Finds the country dropdown
  • Selects India using the visible text

Use Case

Perfect for:

  • Country selection
  • Language selection
  • Payment methods
  • Registration forms

Step 3: Select an Option by Value

await page.selectOption(‘#country’, {

    value: ‘in’

});

Explanation

Instead of matching visible text, Playwright selects the option using the HTML value attribute.

Example

<option value=”in”>India</option>

Use Case

Useful when option labels change but values remain stable.


Step 4: Select an Option by Index

Sometimes, you may want to select an option based on its position in the dropdown instead of its text or value. Playwright allows you to do this using the index property with the selectOption() method.

import { test } from ‘@playwright/test’;

test(‘Select Country by Index’, async ({ page }) => {

    await page.goto(‘https://example.com’);

    await page.selectOption(‘#country’, {

        index: 2

    });

});

Explanation

This script:

  • Opens the application.
  • Locates the country dropdown.
  • Selects the third option (because indexing starts from 0).

Example

<select id=”country”>

    <option>USA</option>

    <option>Canada</option>

    <option>India</option>

</select>

Here:

  • Index 0 → USA
  • Index 1 → Canada
  • Index 2 → India

Use Case

Selecting by index is useful when:

  • Testing dropdown order
  • Working with temporary test environments
  • Option values are unavailable

Note: Selecting by visible text or value is generally more reliable than using indexes.


Step 5: Handle Custom JavaScript Dropdowns

Many modern applications use custom dropdown components built with React, Angular, Vue, or UI libraries like Material UI, PrimeNG, Ant Design, and Bootstrap. These are not standard HTML <select> elements, so selectOption() will not work.

Instead, interact with them using Playwright’s click() and locator() methods.

import { test } from ‘@playwright/test’;

test(‘Select Country from Custom Dropdown’, async ({ page }) => {

    await page.goto(‘https://example.com’);

    await page.locator(‘#countryDropdown’).click();

    await page.locator(‘text=India’).click();

});

Explanation

This script:

  • Opens the dropdown.
  • Displays the available options.
  • Clicks the India option.

Use Case

Common in:

  • React applications
  • Angular Material dropdowns
  • Vue applications
  • Bootstrap Select components
  • Material UI Select controls

Example: React Dropdown

await page.getByRole(‘button’, {

    name: ‘Select Country’

}).click();

await page.getByRole(‘option’, {

    name: ‘India’

}).click();

Practical Scenario

Many enterprise applications use React-based dropdowns for:

  • Customer selection
  • Employee lookup
  • Project assignment
  • Department selection

Step 6: Handle Searchable Dropdowns

Searchable dropdowns allow users to type before selecting an option.

Examples include:

  • Employee search
  • Customer lookup
  • Country search
  • Product search

Example:

await page.locator(‘#countrySearch’).fill(‘India’);

await page.locator(‘text=India’).click();

Explanation

This script:

  • Types India into the search field.
  • Waits for matching options.
  • Selects the correct country.

Use Case

Frequently used in:


Step 7: Select Multiple Options

Some HTML dropdowns allow users to select multiple values.

Example HTML:

<select id=”skills” multiple>

<option value=”java”>Java</option>

<option value=”python”>Python</option>

<option value=”playwright”>Playwright</option>

</select>

Playwright example:

await page.selectOption(‘#skills’, [

‘java’,

‘playwright’

]);

Explanation

Playwright selects both options in one command.

Use Case

Useful for:

  • Skills selection
  • User roles
  • Categories
  • Product tags
  • Team assignments

Step 8: Verify Selected Option

Good automation doesn’t stop after selecting an option—it verifies that the correct option was selected.

import { expect } from ‘@playwright/test’;

await expect(page.locator(‘#country’)).toHaveValue(‘in’);

Explanation

This assertion checks that India is the selected value.

Why Is This Important?

Without verification, your test may pass even if the dropdown selection failed.


Workflow Diagram

Locate Dropdown

       │

       ▼

Select Option

       │

       ▼

Application Updates

       │

       ▼

Verify Selected Value

       │

       ▼

Test Pass


Real-World Dropdown Automation Examples

1. Country and State Selection

await page.selectOption(‘#country’, ‘India’);

await page.selectOption(‘#state’, ‘Karnataka’);

Expected Result

  • India is selected.
  • Karnataka options become available.
  • The correct state is selected successfully.

2. Product Category Filter

await page.selectOption(‘#category’, ‘Electronics’);

Use Case

Common in:

  • Amazon-style applications
  • E-commerce websites
  • Online marketplaces

Expected Result:

Only electronic products appear in the product list.


3. Language Selection

await page.selectOption(‘#language’, ‘English’);

Use Case

Applications supporting multiple languages.

Expected Result:

The application’s language changes to English.


4. Currency Selection

await page.selectOption(‘#currency’, ‘USD’);

Practical Scenario

Used in:

  • Banking portals
  • Travel booking websites
  • Shopping applications

Expected Result:

Product prices refresh and display in the selected currency.


5. Date and Time Dropdowns

await page.selectOption(‘#month’, ‘July’);

await page.selectOption(‘#year’, ‘2026’);

Use Case

Common in:

  • Appointment booking systems
  • Flight booking portals
  • Hotel reservation applications

Expected Result:

The selected month and year appear correctly.


6. Dynamic Search-Based Dropdown

await page.fill(‘#employeeSearch’, ‘John’);

await page.click(‘text=John Smith’);

Practical Scenario

Enterprise applications often load employee names dynamically after typing a few characters.

Expected Result:

The matching employee is selected successfully.

Page Object Model (POM) for Dropdown Handling

As your Playwright automation framework grows, repeating dropdown selection code across multiple test cases can make maintenance difficult. The Page Object Model (POM) solves this problem by placing all dropdown-related methods inside page classes.

LoginPage.ts

import { Page } from ‘@playwright/test’;

export class RegistrationPage {

    constructor(private page: Page) {}

    async selectCountry(country: string) {

        await this.page.selectOption(‘#country’, {

            label: country

        });

    }

    async selectState(state: string) {

        await this.page.selectOption(‘#state’, {

            label: state

        });

    }

    async selectLanguage(language: string) {

        await this.page.selectOption(‘#language’, {

            label: language

        });

    }

}

Using the Page Object

import { test } from ‘@playwright/test’;

import { RegistrationPage } from ‘../pages/RegistrationPage’;

test(‘Registration Form’, async ({ page }) => {

    const registration = new RegistrationPage(page);

    await page.goto(‘https://example.com’);

    await registration.selectCountry(‘India’);

    await registration.selectState(‘Karnataka’);

    await registration.selectLanguage(‘English’);

});

Benefits

Using the Page Object Model provides:


Playwright vs Selenium for Dropdown Handling

FeaturePlaywrightSelenium
HTML Dropdown SupportselectOption()Select class
Custom Dropdown SupportExcellentSupported
Select by TextYesYes
Select by ValueYesYes
Select by IndexYesYes
Multi-select SupportBuilt-inBuilt-in
Automatic WaitingYesLimited
Cross-Browser SupportChromium, Firefox, WebKitBrowser dependent
CI/CD IntegrationExcellentExcellent
Ease of UseVery EasyModerate

Why Many Teams Prefer Playwright

Compared to Selenium, Playwright offers:

  • Built-in auto waiting
  • Less synchronization code
  • Better reliability
  • Faster execution
  • Modern browser support
  • Easier API for dropdown handling

Best Practices for Dropdown Automation

Follow these recommendations to build stable and maintainable automation scripts.

1. Use Reliable Locators

Prefer stable locators like:

page.getByRole()

page.getByLabel()

page.getByTestId()

Avoid fragile XPath expressions whenever possible.


2. Wait for Dynamic Data

Dynamic dropdowns load options asynchronously.

Instead of using:

await page.waitForTimeout(5000);

Use Playwright’s automatic waiting:

await page.locator(‘#country’).waitFor();


3. Reuse Page Object Methods

Avoid writing dropdown logic repeatedly.

Create reusable methods like:

selectCountry()

selectLanguage()

selectCategory()

This improves readability and maintainability.


4. Validate Selected Options

Always verify the selected value.

await expect(page.locator(‘#country’))

    .toHaveValue(‘in’);

Assertions ensure your automation validates actual application behavior.


5. Test Dynamic Dropdowns

Always verify:

  • Options load correctly
  • Duplicate values don’t appear
  • Correct values are displayed
  • Invalid options are absent

6. Integrate Dropdown Tests into CI/CD

Dropdown functionality should be included in every regression suite.

Example GitHub Actions workflow:

name: Playwright Tests

on:

  push:

    branches:

      – main

jobs:

  test:

    runs-on: ubuntu-latest

    steps:

      – uses: actions/checkout@v4

      – uses: actions/setup-node@v4

        with:

          node-version: 20

      – run: npm ci

      – run: npx playwright install –with-deps

      – run: npx playwright test

Expected Outcome

Every code commit automatically executes dropdown automation tests, helping teams detect UI issues before deployment.


Recommended Project Structure

playwright-project/

tests/

pages/

utils/

fixtures/

reports/

playwright.config.ts

Keeping dropdown methods inside page classes makes the framework easier to maintain as it grows.


Common Dropdown Issues and Troubleshooting Tips

Issue 1: Element Not Found

Cause

Incorrect locator.

Solution

Verify the selector using Playwright Inspector.

Example:

await page.locator(‘#country’).click();


Issue 2: Option Not Available

Cause

Dropdown options have not loaded yet.

Solution

Wait until the option becomes visible before selecting it.

await page.locator(‘text=India’).waitFor();

await page.locator(‘text=India’).click();


Issue 3: Dynamic Loading Delays

Cause

AJAX request is still loading data.

Solution

Wait for the dropdown contents instead of using hard-coded delays.


Issue 4: Hidden or Disabled Dropdown

Cause

The dropdown is hidden until another action is performed.

Solution

Perform prerequisite actions before selecting the option.

Example:

await page.click(‘#showCountry’);

await page.selectOption(‘#country’, ‘India’);


Issue 5: Synchronization Problems

Cause

Selection occurs before the dropdown is ready.

Solution

Leverage Playwright’s built-in auto-waiting and avoid waitForTimeout() whenever possible.


Playwright Dropdown Interview Questions with Answers

1. Which Playwright method is used for HTML dropdowns?

The selectOption() method is used to select options from standard HTML <select> elements.


2. Can Playwright automate React or Angular dropdowns?

Yes. Custom dropdowns can be automated using click(), locator(), and accessibility-based locators such as getByRole().


3. How do you select multiple options in Playwright?

Pass an array of values to the selectOption() method.

await page.selectOption(‘#skills’, [

    ‘java’,

    ‘playwright’

]);


4. What is the difference between selecting by label, value, and index?

  • Label selects the visible text.
  • Value selects the HTML value attribute.
  • Index selects the option based on its position.

5. Why is selectOption() preferred for HTML dropdowns?

Because it is simple, reliable, and automatically waits for the dropdown element to become ready.


FAQs – How to Handle Dropdown in Playwright

Q1. What is dropdown handling in Playwright?

Dropdown handling in Playwright is the process of selecting one or more options from HTML or custom dropdown elements using Playwright APIs such as selectOption() and locator().


Q2. Is how to handle dropdown in Playwright suitable for beginners?

Yes. Playwright provides a simple API with automatic waiting, making dropdown automation easy for beginners and experienced QA engineers alike.


Q3. What are the benefits of how to handle dropdown in Playwright?

Benefits include faster automation, reliable execution, cross-browser testing, automatic waiting, easy maintenance, and seamless CI/CD integration.


Q4. Can Playwright automate searchable and dynamic dropdowns?

Yes. Playwright supports searchable and AJAX-based dropdowns using fill(), click(), locator(), and built-in synchronization.


Q5. Can Playwright handle React, Angular, and Vue dropdowns?

Absolutely. Playwright can automate modern JavaScript framework dropdowns by interacting with the underlying UI elements using robust locators.

Leave a Comment

Your email address will not be published. Required fields are marked *