browserSelectOption
Selects specified options in a dropdown menu on a webpage, using the element's xpath reference and providing a delay for snapshot capture, optimizing web interactions within the 'Better Playwright MCP' framework.
Instructions
在下拉框中选择选项
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pageId | Yes | 页面ID | |
| ref | Yes | 元素的xp引用值 | |
| values | Yes | 要选择的选项值数组 | |
| waitForTimeout | No | 操作后等待获取快照的延迟时间(毫秒,默认2000) |
Implementation Reference
- lib/tools/snapshot.js:124-131 (handler)The handler function for the 'browser_select_option' tool. It generates a locator from the element reference, adds code to select the specified options for code generation purposes, and executes the selection in the actual browser tab.handle: async (tab, params, response) => { response.setIncludeSnapshot(); const locator = await tab.refLocator(params); response.addCode(`await page.${await generateLocator(locator)}.selectOption(${javascript.formatObject(params.values)});`); await tab.waitForCompletion(async () => { await locator.selectOption(params.values); }); },
- lib/tools/snapshot.js:112-123 (schema)Defines the Zod schema for the tool inputs: element/ref from shared elementSchema, plus 'values' array of strings to select. Includes the tool schema with name 'browser_select_option'.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 = defineTabTool({ capability: 'core', schema: { name: 'browser_select_option', title: 'Select option', description: 'Select an option in a dropdown', inputSchema: selectOptionSchema, type: 'destructive', },
- lib/tools/snapshot.js:133-139 (registration)Registers the selectOption tool by including it in the default export array of snapshot-related tools, likely imported and registered in the MCP server.export default [ snapshot, click, drag, hover, selectOption, ];
- lib/tools/snapshot.js:34-37 (schema)Shared base schema for element selection tools, extended by browser_select_option for element/ref identification.export const elementSchema = z.object({ element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'), ref: z.string().describe('Exact target element reference from the page snapshot'), });