Skip to main content
Glama
livoras

Better Playwright MCP

by livoras

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
NameRequiredDescriptionDefault
pageIdYes页面ID
refYes元素的xp引用值
valuesYes要选择的选项值数组
waitForTimeoutNo操作后等待获取快照的延迟时间(毫秒,默认2000)

Implementation Reference

  • 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); }); },
  • 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', },
  • 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, ];
  • 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'), });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/livoras/better-playwright-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server