get_element_text
Extract text content from UI elements in Tauri desktop applications using CSS selectors for automated testing and content verification.
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)Primary handler for 'get_element_text' tool. Calls driver.getElementText with the provided selector and returns a standardized 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/tauri-driver.ts:167-176 (helper)Core implementation in TauriDriver class that locates the element by CSS selector using WebDriver and retrieves its text content.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(); }
- src/index.ts:161-170 (schema)Input schema defining the required 'selector' parameter as a string for the tool.inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector to identify the element', }, }, required: ['selector'], },
- src/index.ts:158-171 (registration)Tool registration entry in the ListToolsRequestSchema handler, specifying name, description, and input schema.{ 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-308 (registration)Dispatch logic in the CallToolRequestSchema handler switch statement that invokes the getElementText handler.case 'get_element_text': { const result = await getElementText(driver, args as any); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }