browser_select_option
Select options in dropdown menus during browser automation. Specify element references and values to interact with web page controls programmatically.
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:201-216 (handler)The core handler function that executes the 'browser_select_option' tool logic. It locates the target element using the page snapshot reference, generates Playwright code for selecting options, and defines an action to perform the selection.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:193-199 (schema)The schema definition for the 'browser_select_option' tool, specifying name, title, description, input schema, and type.schema: { name: 'browser_select_option', title: 'Select option', description: 'Select an option in a dropdown', inputSchema: selectOptionSchema, type: 'destructive', },
- src/tools/snapshot.ts:187-189 (schema)Zod input schema extension defining the 'values' parameter as an array of strings for the options 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.'), });
- src/tools/snapshot.ts:191-217 (registration)The defineTool call that creates the 'browser_select_option' tool object, combining schema and handler. Exported for further registration.const selectOption = defineTool({ capability: 'core', schema: { name: 'browser_select_option', title: 'Select option', description: 'Select an option in a dropdown', inputSchema: selectOptionSchema, type: 'destructive', }, 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.ts:47-47 (registration)Inclusion of tools from snapshot.ts (including browser_select_option) into the main snapshotTools array for global registration....snapshot,