get_text
Extract text content from web elements using CSS selectors for browser automation and web scraping tasks.
Instructions
Get text content from an element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for the element |
Implementation Reference
- tools-playwright.js:173-187 (registration)Registration of the 'get_text' tool in the Playwright tools array, including name, description, input schema, and handler function that delegates to browser.getText(){ name: 'get_text', description: 'Get text content from an element', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector for the element' } }, required: ['selector'] }, handler: async ({ selector }) => { const text = await browser.getText(selector); return { success: true, data: { text }, message: `Got text from ${selector}` }; } },
- browser.js:106-109 (handler)Core implementation of getText method in SimpleBrowser class using Playwright's page.textContent to extract text from the specified selectorasync getText(selector) { await this.ensureLaunched(); return await this.page.textContent(selector); }
- index.js:74-76 (registration)Main registration point where createTools is called to include 'get_text' (via playwrightTools) in the MCP server's tools list used for listTools and callTool requests// Register all available automation tools const tools = createTools(browser);
- tools-playwright.js:176-182 (schema)Input schema definition for the 'get_text' tool requiring a CSS selectorinputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector for the element' } }, required: ['selector'] },
- tools.js:17-21 (registration)Combines playwrightTools (including get_text) with other tools into the main tools array for MCP server registrationexport function createTools(browser) { const playwrightTools = createPlaywrightTools(browser); return [ ...playwrightTools,