browser_select_text
Automate selecting elements by text on web pages for security testing, enabling precise interaction during penetration tests like XSS and SQL injection checks.
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:424-463 (handler)The main handler logic for the 'browser_select_text' tool within the handleToolCall function's switch statement. It attempts to select an option in a select dropdown element located by its text content using Playwright's getByText and selectOption methods, with error handling and retry 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, }; }
- index.ts:121-132 (registration)Registration of the 'browser_select_text' tool in the TOOLS array. This defines the tool's name (referencing the ToolName enum), description, and input schema, which is later served via ListToolsRequestSchema.{ 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:124-131 (schema)Input schema definition for the 'browser_select_text' tool, specifying required string parameters 'text' and 'value' for locating the select element and the option to select.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:29-29 (helper)Enum value in ToolName defining the string identifier 'browser_select_text' used for tool name in registration and handler dispatch.BrowserSelectText = "browser_select_text",