get_element_text
Extract text content from UI elements in Tauri desktop applications using CSS selectors for automation and testing workflows.
Instructions
Get the text content of an element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector to identify the element |
Implementation Reference
- src/tools/interact.ts:83-102 (handler)The handler function that executes the get_element_text tool logic. It calls the TauriDriver's getElementText method and wraps the result in a ToolResponse.export async function getElementText( driver: TauriDriver, params: ElementSelector ): Promise<ToolResponse<{ text: string }>> { try { const text = await driver.getElementText(params.selector); return { success: true, data: { text, }, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error), }; } }
- src/index.ts:158-171 (schema)The input schema definition for the get_element_text tool, registered in the ListTools handler.{ name: 'get_element_text', description: 'Get the text content of an element', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector to identify the element', }, }, required: ['selector'], }, },
- src/index.ts:298-307 (registration)The registration/dispatch case in the CallToolRequestSchema handler that invokes the getElementText function.case 'get_element_text': { const result = await getElementText(driver, args as any); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], };
- src/tauri-driver.ts:167-176 (helper)The underlying TauriDriver method that performs the actual element text retrieval using WebDriverIO.async getElementText(selector: string): Promise<string> { this.ensureAppRunning(); const element = await this.appState.browser!.$(selector); if (!(await element.isExisting())) { throw new Error(`Element not found: ${selector}`); } return await element.getText(); }