Skip to main content
Glama

browser_get_element_text

Extract text content from web page elements using CSS selectors within browser automation workflows. Retrieve visible text from specified elements to gather data or verify content during automated browsing sessions.

Instructions

Get element text content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instanceIdYesInstance ID
selectorYesElement selector
timeoutNoTimeout in milliseconds

Implementation Reference

  • The handler function that executes the browser_get_element_text tool. It retrieves the browser instance, waits for and gets the text content of the element matching the selector using Playwright's page.textContent method, and returns the result or error.
    private async getElementText(instanceId: string, selector: string, timeout: number): Promise<ToolResult> {
      const instance = this.browserManager.getInstance(instanceId);
      if (!instance) {
        return { success: false, error: `Instance ${instanceId} not found` };
      }
    
      try {
        const text = await instance.page.textContent(selector, { timeout });
        return {
          success: true,
          data: { selector, text },
          instanceId
        };
      } catch (error) {
        return {
          success: false,
          error: `Get element text failed: ${error instanceof Error ? error.message : error}`,
          instanceId
        };
      }
    }
  • The input schema definition for the browser_get_element_text tool, specifying required instanceId and selector, optional timeout.
    {
      name: 'browser_get_element_text',
      description: 'Get element text content',
      inputSchema: {
        type: 'object',
        properties: {
          instanceId: {
            type: 'string',
            description: 'Instance ID'
          },
          selector: {
            type: 'string',
            description: 'Element selector',
          },
          timeout: {
            type: 'number',
            description: 'Timeout in milliseconds',
            default: 30000
          }
        },
        required: ['instanceId', 'selector']
      }
  • src/tools.ts:307-329 (registration)
    The tool registration in the getTools() method's return array, defining the tool name, description, and input schema.
    {
      name: 'browser_get_element_text',
      description: 'Get element text content',
      inputSchema: {
        type: 'object',
        properties: {
          instanceId: {
            type: 'string',
            description: 'Instance ID'
          },
          selector: {
            type: 'string',
            description: 'Element selector',
          },
          timeout: {
            type: 'number',
            description: 'Timeout in milliseconds',
            default: 30000
          }
        },
        required: ['instanceId', 'selector']
      }
    },
  • src/tools.ts:556-558 (registration)
    The switch case in executeTools that dispatches to the getElementText handler for this tool.
    case 'browser_get_element_text':
      return await this.getElementText(args.instanceId, args.selector, args.timeout || 30000);
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral context. It doesn't disclose that this is a read-only operation (implied by 'Get'), doesn't mention potential failures (e.g., if element isn't found or isn't visible), and doesn't describe return format or error handling. The timeout parameter suggests it might wait for elements, but this isn't explicitly explained.

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 maximally concise with just four words that directly state the tool's function. There's zero waste or redundancy, and the information is front-loaded appropriately for such a simple operation.

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

Completeness2/5

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

For a browser automation tool with 3 parameters and no output schema, the description is inadequate. It doesn't explain what 'text content' means (innerText vs textContent), doesn't mention the tool's relationship to other browser tools, and provides no information about return values or error conditions despite the complexity of browser interactions.

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 description coverage is 100%, so the schema already documents all three parameters adequately. The description adds no additional parameter semantics beyond what's in the schema - it doesn't explain selector syntax, instanceId format, or timeout behavior. Baseline 3 is appropriate when schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the verb ('Get') and resource ('element text content'), making the purpose immediately understandable. However, it doesn't distinguish this tool from its sibling 'browser_get_element_attribute', which also retrieves element properties but for attributes rather than text content.

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?

The description provides no guidance on when to use this tool versus alternatives like 'browser_get_element_attribute' or 'browser_get_markdown'. It also doesn't mention prerequisites such as needing an existing browser instance or when text extraction is appropriate versus other retrieval methods.

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

Install Server

Other 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/sailaoda/concurrent-browser-mcp'

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