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
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector of the element |
Implementation Reference
- src/browser.ts:72-81 (handler)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}`); } }
- src/index.ts:60-70 (schema)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;