Skip to main content
Glama

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

Implementation Reference

  • 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, }; }
  • 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 ?? {}) );
  • Enum definition mapping ToolName.BrowserSelectText to the string 'browser_select_text'.
    BrowserSelectText = "browser_select_text",

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/Automata-Labs-team/MCP-Server-Playwright'

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