Skip to main content
Glama

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
NameRequiredDescriptionDefault
textYesText content of the element to select
valueYesValue to select

Implementation Reference

  • 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"], }, },
  • 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"], },
  • Enum value in ToolName defining the string identifier 'browser_select_text' used for tool name in registration and handler dispatch.
    BrowserSelectText = "browser_select_text",

Other Tools

Related Tools

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/9olidity/MCP-Server-Pentest'

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