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);

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