← Back to library
Playwrightformsbeginnerv1.20+

Select from a dropdown

Select an option by label, value, or index from a native <select> element.

1test('selects an option', async ({ page }) => {
2  await page.goto('/settings');
3
4  const select = page.locator('select[name="country"]');
5
6  // By visible label
7  await select.selectOption({ label: 'Egypt' });
8
9  // By value attribute
10  // await select.selectOption({ value: 'EG' });
11
12  // By index (0-based)
13  // await select.selectOption({ index: 2 });
14
15  await expect(select).toHaveValue('EG');
16});
#select#dropdown#forms