Skip to main content
Glama

get_element_text

Extract text content from a web element using a CSS selector with the MCP Browser Server, enabling automated data retrieval from web pages.

Instructions

Get text content of an element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for the element
timeoutNoTimeout in milliseconds

Implementation Reference

  • Handler for 'get_element_text' tool: checks for current page, parses input parameters using GetElementTextSchema, retrieves the text content of the specified element using Playwright's page.textContent method with timeout, and returns the extracted text.
    case 'get_element_text': { if (!currentPage) { throw new Error('No browser page available. Launch a browser first.'); } const params = GetElementTextSchema.parse(args); const text = await currentPage.textContent(params.selector, { timeout: params.timeout }); return { content: [ { type: 'text', text: `Element text: ${text || '(empty)'}` } ] }; }
  • Zod schema defining the input parameters for the 'get_element_text' tool: CSS selector (required) and optional timeout (default 5000ms).
    const GetElementTextSchema = z.object({ selector: z.string(), timeout: z.number().default(5000) });
  • src/index.ts:237-255 (registration)
    Tool registration in the ListToolsRequestSchema handler, providing name, description, and JSON schema matching the Zod schema for client-side validation.
    { name: 'get_element_text', description: 'Get text content of an element', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector for the element' }, timeout: { type: 'number', default: 5000, description: 'Timeout in milliseconds' } }, required: ['selector'] } },

Other Tools

Related 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/Wladastic/mcp-browser-server'

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