Skip to main content
Glama

browser_get_element_text

Extract text content from web page elements using Selenium WebDriver. Specify locator strategy and value to retrieve text from specific elements during browser automation.

Instructions

Gets the text of an element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
byYesLocator strategy to find element
valueYesValue for the locator strategy
timeoutNoMaximum time to wait for element in milliseconds

Implementation Reference

  • The MCP tool handler function registered for 'browser_get_element_text'. It retrieves the browser driver, instantiates ElementService, fetches the element text, and returns it in the MCP response format, with error handling.
    server.tool(
      'browser_get_element_text',
      'Gets the text of an element',
      { ...locatorSchema },
      async ({ by, value, timeout = 15000 }) => {
        try {
          const driver = stateManager.getDriver();
          const elementService = new ElementService(driver);
          const text = await elementService.getElementText({
            by,
            value,
            timeout,
          });
          return {
            content: [{ type: 'text', text }],
          };
        } catch (e) {
          return {
            content: [
              {
                type: 'text',
                text: `Error getting element text: ${(e as Error).message}`,
              },
            ],
          };
        }
      }
    );
  • Zod-based input schema for the tool parameters (locator strategy, value, optional timeout).
    export const locatorSchema = {
      by: z
        .enum(['id', 'css', 'xpath', 'name', 'tag', 'class', 'link', 'partialLink'])
        .describe('Locator strategy to find element'),
      value: z.string().describe('Value for the locator strategy'),
      timeout: z.number().optional().describe('Maximum time to wait for element in milliseconds'),
    };
  • The ElementService method implementing the core logic: finds the element using the locator and retrieves its text using Selenium WebDriver's getText().
    async getElementText(params: LocatorParams): Promise<string> {
      const element = await this.findElement(params);
      return element.getText();
    }
  • Call to register the element tools, including 'browser_get_element_text', within the overall tools registration.
    registerElementTools(server, stateManager);
  • Supporting findElement method used by getElementText to locate the WebElement.
    async findElement(params: LocatorParams): Promise<WebElement> {
      const locator = LocatorFactory.createLocator(params.by, params.value);
      return this.driver.wait(until.elementLocated(locator), params.timeout || 15000);
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. 'Gets the text of an element' implies a read-only operation but doesn't disclose behavioral traits like whether it waits for the element (hinted by timeout param), handles hidden elements, returns empty strings, or throws errors for missing elements. This leaves significant gaps for agent understanding.

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, efficient sentence with zero waste. It's front-loaded with the core purpose, making it easy to parse quickly. Every word earns its place without redundancy or fluff.

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?

Given no annotations and no output schema, the description is incomplete for a tool with 3 parameters and behavioral complexity. It doesn't explain return values (e.g., string format, null cases), error conditions, or interaction with browser state, leaving the agent under-informed for reliable use.

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%, with clear parameter descriptions in the schema (e.g., 'Locator strategy to find element' for 'by'). The description adds no additional parameter semantics beyond what the schema provides, so it meets the baseline of 3 without compensating or detracting.

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 'Gets the text of an element' clearly states the verb ('Gets') and resource ('text of an element'), making the purpose immediately understandable. It distinguishes from siblings like browser_get_attribute or browser_find_element by specifying text extraction, though it doesn't explicitly contrast with them.

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. It doesn't mention when text extraction is preferred over attribute retrieval (browser_get_attribute) or element finding (browser_find_element), nor does it specify prerequisites like needing an open browser or element visibility.

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/pshivapr/selenium-mcp'

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