browser_select_option
Select options in dropdown menus during browser automation by specifying element references and values to choose.
Instructions
Select an option in a dropdown
Input 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:209-225 (handler)The handler function that implements the core logic of the 'browser_select_option' tool. It retrieves the page snapshot, locates the target dropdown element, generates code for selecting options, and performs the selection using Playwright's locator.selectOption method.
handle: async (context, params) => { const snapshot = context.currentTabOrDie().snapshotOrDie(); const locator = snapshot.refLocator(params); const code = [ `// Select options [${params.values.join(', ')}] in ${params.element}`, `await page.${await generateLocator(locator)}.selectOption(${javascript.formatObject(params.values)});` ]; return { code, action: () => locator.selectOption(params.values).then(() => {}), captureSnapshot: true, waitForNetwork: true, }; }, }); - src/tools/snapshot.ts:195-207 (schema)Zod schema defining the input for 'browser_select_option': requires element description and ref from snapshot, plus array of values to select.
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.'), }); const selectOption = defineTool({ capability: 'core', schema: { name: 'browser_select_option', title: 'Select option', description: 'Select an option in a dropdown', inputSchema: selectOptionSchema, type: 'destructive', }, - src/tools/snapshot.ts:227-234 (registration)Local registration of the 'browser_select_option' tool (as selectOption) within the array exported from snapshot.ts for further aggregation.
export default [ snapshot, click, drag, hover, type, selectOption, ]; - src/tools.ts:35-50 (registration)Global registration: imports and includes all tools from snapshot.ts (including browser_select_option) into the snapshotTools array used by the MCP server.
export const snapshotTools: Tool<any>[] = [ ...common(true), ...console, ...dialogs(true), ...files(true), ...install, ...keyboard(true), ...navigate(true), ...network, ...pdf, ...screenshot, ...snapshot, ...tabs(true), ...testing, ...wait(true), ];