browser_select_text
Select a dropdown option by matching its visible text, then apply the specified value.
Instructions
Select an element on the page with Select tag by its text content
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text content of the element to select | |
| value | Yes | Value to select |
Implementation Reference
- index.ts:29-29 (registration)Enum entry registering the tool name 'browser_select_text'
BrowserSelectText = "browser_select_text", - index.ts:107-118 (schema)Tool schema definition for BrowserSelectText, specifying input validation with 'text' and 'value' required string properties
{ 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:398-437 (handler)Handler implementation for BrowserSelectText: finds element by text content using page.getByText(), then selects the specified option value. Includes retry logic with .first() for strict mode violations.
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, }; }