Skip to main content
Glama

get_text

Extract text content from web elements using CSS selectors for automated testing and content verification in browser automation workflows.

Instructions

Get the text content of an element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector of the element

Implementation Reference

  • The main handler function for the 'get_text' tool. It initializes the browser page if needed, waits for the CSS selector, extracts the text content using Puppeteer, trims it, and returns it or throws an error.
    async getText(selector: string) { const page = await this.init(); try { await page.waitForSelector(selector, { timeout: 5000 }); const text = await page.$eval(selector, el => el.textContent); return text?.trim() || ''; } catch (e: any) { throw new Error(`Failed to get text from ${selector}: ${e.message}`); } }
  • Tool schema definition including name, description, and inputSchema for the 'get_text' tool.
    { name: "get_text", description: "Get the text content of an element", inputSchema: { type: "object", properties: { selector: { type: "string", description: "CSS selector of the element" }, }, required: ["selector"], }, },
  • src/index.ts:129-131 (registration)
    Registration of the 'get_text' tool handler in the switch statement of the CallToolRequestHandler, dispatching to browserManager.getText.
    case "get_text": result = await browserManager.getText(String(args?.selector)); break;

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/samusilv/qa-agent-mcp'

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