browser_select_text
Select dropdown elements in web pages by matching text content to values for automated browser interactions.
Instructions
Select an element on the page with Select tag by its text content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text content of the element to select | |
| value | Yes | Value to select |
Implementation Reference
- index.ts:398-437 (handler)The main handler logic for the 'browser_select_text' tool. It attempts to select an option in a <select> element by matching the text content using Playwright's page.getByText().selectOption(). Includes error handling for strict mode violations by retrying on the first matching element.case ToolName.BrowserSelectText: try { await page.getByText(args.text).selectOption(args.value); return { content: [{ type: "text", text: `Selected element with text ${args.text} with value: ${args.value}`, }], isError: false, }; } catch (error) { if((error as Error).message.includes("strict mode violation")) { console.log("Strict mode violation, retrying on first element..."); try { await page.getByText(args.text).first().selectOption(args.value); return { content: [{ type: "text", text: `Selected element with text ${args.text} with value: ${args.value}`, }], isError: false, }; } catch (error) { return { content: [{ type: "text", text: `Failed (twice) to select element with text ${args.text}: ${(error as Error).message}`, }], isError: true, }; } } return { content: [{ type: "text", text: `Failed to select element with text ${args.text}: ${(error as Error).message}`, }], isError: true, }; }
- index.ts:107-118 (schema)Tool schema definition including name, description, and inputSchema for 'browser_select_text'. Defines required parameters 'text' and 'value'.{ name: ToolName.BrowserSelectText, description: "Select an element on the page with Select tag by its text content", inputSchema: { type: "object", properties: { text: { type: "string", description: "Text content of the element to select" }, value: { type: "string", description: "Value to select" }, }, required: ["text", "value"], }, },
- index.ts:640-642 (registration)Registration of all tools, including 'browser_select_text', via the ListToolsRequestSchema handler which returns the TOOLS array.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS, }));
- index.ts:644-646 (registration)Registration of the CallToolRequestSchema handler, which dispatches to handleToolCall based on the tool name, including 'browser_select_text'.server.setRequestHandler(CallToolRequestSchema, async (request) => handleToolCall(request.params.name as ToolName, request.params.arguments ?? {}) );
- index.ts:29-29 (helper)Enum definition mapping ToolName.BrowserSelectText to the string 'browser_select_text'.BrowserSelectText = "browser_select_text",