Skip to main content
Glama
Automata-Labs-team

MCP-Server-Playwright

browser_click_text

Click web page elements by their visible text content to automate interactions in a browser environment.

Instructions

Click an element on the page by its text content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesText content of the element to click

Implementation Reference

  • Handler for the 'browser_click_text' tool. Uses Playwright's page.getByText() to locate and click an element by its text content. Includes error handling and retry logic for strict mode violations.
    case ToolName.BrowserClickText:
      try {
        await page.getByText(args.text).click();
        return {
          content: [{
            type: "text",
            text: `Clicked element with text: ${args.text}`,
          }],
          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().click();
                return {
                    content: [{
                        type: "text",
                        text: `Clicked element with text: ${args.text}`,
                    }],
                    isError: false,
                };
            } catch (error) {
                return {
                    content: [{
                        type: "text",
                        text: `Failed (twice) to click element with text ${args.text}: ${(error as Error).message}`,
                    }],
                    isError: true,
                };
            }
        }
        return {
          content: [{
            type: "text",
            text: `Failed to click element with text ${args.text}: ${(error as Error).message}`,
          }],
          isError: true,
        };
      }
  • Input schema definition for the 'browser_click_text' tool, specifying a required 'text' string parameter.
    {
      name: ToolName.BrowserClickText,
      description: "Click an element on the page by its text content",
      inputSchema: {
        type: "object",
        properties: {
          text: { type: "string", description: "Text content of the element to click" },
        },
        required: ["text"],
      },
    },
  • index.ts:644-646 (registration)
    Registers the general tool call handler which dispatches to specific tool implementations including 'browser_click_text' via handleToolCall.
    server.setRequestHandler(CallToolRequestSchema, async (request) =>
      handleToolCall(request.params.name as ToolName, request.params.arguments ?? {})
    );
  • index.ts:640-642 (registration)
    Registers the list tools handler that exposes the 'browser_click_text' tool (via the TOOLS array) to clients.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: TOOLS,
    }));
  • Enum defining tool names, including BrowserClickText = 'browser_click_text' used throughout the code.
    enum ToolName {
      BrowserNavigate = "browser_navigate",
      BrowserScreenshot = "browser_screenshot",
      BrowserClick = "browser_click",
      BrowserClickText = "browser_click_text",
      BrowserFill = "browser_fill",
      BrowserSelect = "browser_select",
      BrowserSelectText = "browser_select_text",
      BrowserHover = "browser_hover",
      BrowserHoverText = "browser_hover_text",
      BrowserEvaluate = "browser_evaluate"
    }

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