browser_select_option
Select values in dropdown menus during browser automation. Use this Playwright MCP tool to interact with web page dropdowns by specifying element references and desired values.
Instructions
Select an option in a dropdown
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| element | Yes | Human-readable element description used to obtain permission to interact with the element | |
| ref | Yes | Exact target element reference from the page snapshot | |
| values | Yes | Array of values to select in the dropdown. This can be a single value or multiple values. |
Implementation Reference
- src/tools/snapshot.ts:175-186 (handler)Implements the core logic for the browser_select_option tool: parses input using selectOptionSchema, locates the target element via snapshot reference, generates explanatory Playwright code snippet, performs the selectOption action on the locator, and returns the code.
handle: async (context, params) => { const validatedParams = selectOptionSchema.parse(params); return await context.currentTab().runAndWaitWithSnapshot(async snapshot => { const locator = snapshot.refLocator(validatedParams.ref); const code = [ `// Select options [${validatedParams.values.join(', ')}] in ${validatedParams.element}`, `await page.${await generateLocator(locator)}.selectOption(${javascript.formatObject(validatedParams.values)});` ]; await locator.selectOption(validatedParams.values); return { code }; }); }, - src/tools/snapshot.ts:169-173 (schema)Defines the tool schema including name 'browser_select_option', description, and input schema derived from selectOptionSchema.
schema: { name: 'browser_select_option', description: 'Select an option in a dropdown', inputSchema: zodToJsonSchema(selectOptionSchema), }, - src/tools/snapshot.ts:163-165 (schema)Zod type definition for the input schema of browser_select_option, extending shared elementSchema with 'values' array parameter.
const selectOptionSchema = elementSchema.extend({ values: z.array(z.string()).describe('Array of values to select in the dropdown. This can be a single value or multiple values.'), }); - src/tools/snapshot.ts:246-246 (registration)Registers the browser_select_option tool by including the selectOption object in the exported array of tools from this module.
selectOption,