get_text
Extract text content from web elements using CSS selectors for automated testing and content verification.
Instructions
Get the text content of an element
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"selector": "<selector>"
},
"name": "get_text"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector of the element |
Implementation Reference
- src/browser.ts:72-81 (handler)Core implementation of get_text tool: waits for the selector and extracts the textContent of the element using Puppeteer.
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 (registration)Tool registration in the TOOLS array: defines name, description, and input schema for listTools response.
{ 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 (handler)Handler dispatcher in CallToolRequestSchema: routes get_text calls to browserManager.getText.
case "get_text": result = await browserManager.getText(String(args?.selector)); break;