Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

In this tutorial, learn how to handle Playwright alerts and dropdowns including prompt and modal alerts, plus single-select, multi-select, and more.

Mehul Gadhiya
March 15, 2026
When you work with Playwright, alerts and dropdowns often appear as part of normal web application flow. Knowing how to handle Playwright alerts and dropdowns allows you to keep your automated tests running without interruption.
By handling these elements the right way, you can avoid unexpected test failures, match real user actions more closely, and ensure your tests give consistent results.
Overview
How to Handle Playwright Alerts?
Playwright lets you work with browser dialogs like alerts, confirms, and prompts through thepage.on('dialog') event. You can listen for these dialogs, read their messages, and choose whether to accept or dismiss them.
How to Handle Playwright Dropdowns?
Dropdowns in Playwright can be managed by using select_option() or standard locators when working with custom UI components. These methods allow you to pick values by label, index, or value attributes.
Playwright alerts are browser dialogs that appear during page execution to show messages or request user actions like confirmations and text input.
Here, you’ll rely heavily on good Playwright functions and selectors since alerts and dropdowns often appear only after user interaction, and these functions and selectors make targeting those elements much more reliable.
Note: Run Playwright tests across over 3000 real environments. Try TestMu AI Now!
Playwright allows handling prompt alerts and modal dialogs that interrupt normal page interaction. Prompt alerts can be handled using page.on("dialog") to provide input, and modal dialogs are handled via standard DOM interactions.
Prompt alerts request input from the user and pause interaction until a value is entered and OK or Cancel is clicked.
Test Scenario:
Implementation:
The test script below listens for the prompt alert, enters a value, and verifies that the text appears in the output.
import { expect, test } from "@playwright/test";
test("Prompt alert", async ({ page }) => {
await page.goto("https://www.lambdatest.com/selenium-playground/javascript-alert-box-demo
");
page.on("dialog", async (alert) => {
console.log(alert.message());
await alert.accept("koushik");
});
await page.locator("button:has-text('Click Me')").nth(2).click();
await expect(page.locator("#prompt-demo")).toContainText("'koushik'");
});
Code Walkthrough:
Modal alerts are page-based pop-ups that appear over the main content to capture attention. They are handled using standard DOM interactions rather than browser-level dialog methods.
Test Scenario:
Implementation:
The test script below interacts with a Bootstrap modal by clicking the buttons using standard selectors.
import { test } from "@playwright/test";
test("Modal alert", async ({ page }) => {
await page.goto("https://www.lambdatest.com/selenium-playground/bootstrap-modal-demo
");
await page.click("//button[@data-target='#myModal']");
await page.click("(//button[text()='Save Changes'])[1]");
});Code Walkthrough:
Since modals rely on precise DOM clicks, understanding the Playwright click() method helps you handle edge cases like overlapping elements or delayed rendering.
Once an alert is handled, Playwright assertions help confirm the page updated as expected, whether that’s a message appearing or a field changing value.
Test Execution:
Now, let's run the test for Playwright alerts (prompt and modal) using the following command:
npx playwright test tests/alerts.test.ts
You can also check out this video on handling Playwright alerts by Vignesh Srinivasa Raghavan, a Senior SDET with 10+ years of expertise in software automation testing, specializing in web, mobile, API, and performance testing.
Playwright dropdowns are HTML elements that let you select one or more options from a list, typically built with the <select> tag or custom UI controls.
Dropdowns can be single-select or multi-select, and interacting with them requires choosing the correct option by value, label, or index. If you also need to automate other form elements, check out the guide on handling inputs and buttons in Playwright.
Dropdowns allow you to select single or multiple options. Playwright provides selectOption() for standard HTML <select> elements, and standard DOM interactions for custom dropdowns like Bootstrap or jQuery-based dropdowns.
Note: The page.selectOption() method is discouraged by Playwright. Use the locator-based locator.selectOption() instead for more reliable and maintainable tests.
Single-select dropdowns allow choosing only one option at a time.
Test Scenario:
Implementation:
The test script below selects an option from a single-select dropdown.
import { test } from "@playwright/test";
test("Single-select dropdown", async ({ page }) => {
await page.goto("https://www.lambdatest.com/selenium-playground/select-dropdown-demo");
await page.selectOption("#select-demo", {
index: 5 // alternatively, use label: "Tuesday" or value: "Friday"
});
});Code Walkthrough:
Multi-select dropdowns allow selecting multiple options simultaneously.
Test Scenario:
Implementation:
import { test } from "@playwright/test";
test("Multi-select dropdown", async ({ page }) => {
await page.goto("https://www.lambdatest.com/selenium-playground/select-dropdown-demo");
await page.selectOption("#multi-select", [
{ label: "Texas" },
{ index: 2 },
{ value: "Washington" }
]);
});Code Walkthrough:
Custom dropdowns like Bootstrap or jQuery require opening the menu and selecting items using DOM locators. Choosing the right targeting strategy is critical here, so having a solid understanding of Playwright locators makes your dropdown tests more resilient to UI changes.
Test Scenario:
Implementation:
import { test } from "@playwright/test";
test("Bootstrap/jQuery dropdown", async ({ page }) => {
await page.goto("https://www.lambdatest.com/selenium-playground/jquery-dropdown-search-demo");
await selectCountry("India");
await selectCountry("Denmark");
await selectCountry("South Africa");
async function selectCountry(countryName) {
await page.click("#country+span");
await page.locator("ul#select2-country-results")
.locator("li", { hasText: countryName })
.click();
}
});Code Walkthrough:
Test Execution:
Now, let's run the test for Playwright dropdowns using the following command:
npx playwright test tests/dropdown.test.ts
You can leverage the true capabilities of the Playwright test automation framework by running the test on cloud grids like TestMu AI.
Cloud testing platforms like TestMu AI offers Playwright cloud that allows you to run Playwright tests online on 50+ browsers and browser versions such as Chrome, Firefox, Opera, Edge, etc.
To get started, check out this documentation on Playwright testing with TestMu AI.
You now have a clear view of how Playwright handles alerts and dropdowns. You can detect, read, and control alerts, including prompts and modal dialogs, without interrupting your test flow.
You can also manage single-select, multi-select, and custom dropdowns with direct, reliable interactions. With these skills, you can create stable tests that handle real user scenarios and respond accurately to page behavior. To continue building on this, learn how to automate frames and windows in Playwright for multi-context test scenarios.
Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance