Skip to main content
Glama
VikashLoomba

MCP-Server-Playwright

by VikashLoomba

browser_click_text

Clicks a web page element identified by its visible text content. Useful for interacting with links, buttons, or any clickable text element.

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

  • index.ts:22-33 (registration)
    Tool name enum definition for browser_click_text
    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"
    }
  • Input schema for browser_click_text tool - accepts a '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"],
      },
    },
  • Handler implementation: uses page.getByText(args.text).click() to find and click an element by its visible text content, with strict mode violation retry logic
    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,
        };
      }
  • index.ts:36-152 (registration)
    TOOLS array registration including BrowserClickText as part of the tool list
    const TOOLS: Tool[] = [
      {
        name: ToolName.BrowserNavigate,
        description: "Navigate to a URL",
        inputSchema: {
          type: "object",
          properties: {
            url: { type: "string" },
          },
          required: ["url"],
        },
      },
      {
        name: ToolName.BrowserScreenshot,
        description: "Take a screenshot of the current page or a specific element",
        inputSchema: {
          type: "object",
          properties: {
            name: { type: "string", description: "Name for the screenshot" },
            selector: { type: "string", description: "CSS selector for element to screenshot" },
            fullPage: { type: "boolean", description: "Take a full page screenshot (default: false)", default: false },
          },
          required: ["name"],
        },
      },
      {
        name: ToolName.BrowserClick,
        description: "Click an element on the page using CSS selector",
        inputSchema: {
          type: "object",
          properties: {
            selector: { type: "string", description: "CSS selector for element to click" },
          },
          required: ["selector"],
        },
      },
      {
        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"],
        },
      },
      {
        name: ToolName.BrowserFill,
        description: "Fill out an input field",
        inputSchema: {
          type: "object",
          properties: {
            selector: { type: "string", description: "CSS selector for input field" },
            value: { type: "string", description: "Value to fill" },
          },
          required: ["selector", "value"],
        },
      },
      {
        name: ToolName.BrowserSelect,
        description: "Select an element on the page with Select tag using CSS selector",
        inputSchema: {
          type: "object",
          properties: {
            selector: { type: "string", description: "CSS selector for element to select" },
            value: { type: "string", description: "Value to select" },
          },
          required: ["selector", "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"],
        },
      },
      {
        name: ToolName.BrowserHover,
        description: "Hover an element on the page using CSS selector",
        inputSchema: {
          type: "object",
          properties: {
            selector: { type: "string", description: "CSS selector for element to hover" },
          },
          required: ["selector"],
        },
      },
      {
        name: ToolName.BrowserHoverText,
        description: "Hover an element on the page by its text content",
        inputSchema: {
          type: "object",
          properties: {
            text: { type: "string", description: "Text content of the element to hover" },
          },
          required: ["text"],
        },
      },
      {
        name: ToolName.BrowserEvaluate,
        description: "Execute JavaScript in the browser console",
        inputSchema: {
          type: "object",
          properties: {
            script: { type: "string", description: "JavaScript code to execute" },
          },
          required: ["script"],
        },
      },
    ];

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv1.0.0

TDQS

B3.3/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist, so the description must disclose behavioral traits. It does not address what happens if multiple elements match the text, whether it scrolls, if match is exact, or that clicking may trigger navigation. This is insufficient for safe invocation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence that conveys the core functionality without extraneous information. Every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple tool with one parameter and no output schema, the description is minimal but adequate. However, it lacks details on return values, error cases, and behavior with ambiguous matches, leaving some gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, and the description adds no extra meaning beyond the parameter name and schema description. It does not clarify if matching is case-sensitive or partial, so it meets baseline but adds no value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'click' and the resource 'element on the page', and specifies the method 'by its text content', distinguishing it from siblings like browser_click or browser_hover_text.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. There is no mention of when to prefer text-based clicking over coordinate-based clicking or when element uniqueness matters.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.