Last active
February 28, 2026 10:52
-
-
Save pablocattaneo/5c6b2e8b6a5a6fb9185e10fd8b860a14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Selects one or multiple options in the <select> element with locator.selectOption(). You can specify option value, or label to select. Multiple options can be selected. | |
| // Single selection matching the value or label | |
| await page.getByLabel('Choose a color').selectOption('blue'); | |
| // Single selection matching the label | |
| await page.getByLabel('Choose a color').selectOption({ label: 'Blue' }); | |
| // Multiple selected items | |
| await page.getByLabel('Choose multiple colors').selectOption(['red', 'green', 'blue']); | |
| // Example | |
| import { test } from "@playwright/test"; | |
| const PAGE_URL = "https://testautomationpractice.blogspot.com/"; | |
| test("Single select dropdown actions", async ({ page }) => { | |
| await page.goto(PAGE_URL); | |
| const dropdown = page.getByRole("listbox").and(page.locator("#country")); | |
| await dropdown.selectOption("India"); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment