click_element
Automate clicking on UI elements in Tauri desktop applications using CSS selectors to interact with buttons, links, and other interface components for testing and workflow automation.
Instructions
Click a UI element identified by a CSS selector
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector to identify the element to click (e.g., "#button-id", ".button-class", "button[name=submit]") |
Implementation Reference
- src/tools/interact.ts:11-30 (handler)The main handler function for the 'click_element' tool. It receives the driver and parameters, calls the driver's clickElement method, and returns a standardized ToolResponse with success status and message or error.export async function clickElement( driver: TauriDriver, params: ElementSelector ): Promise<ToolResponse<{ message: string }>> { try { await driver.clickElement(params.selector); return { success: true, data: { message: `Clicked element: ${params.selector}`, }, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error), }; } }
- src/index.ts:102-115 (schema)Defines the tool schema including name, description, and input schema (CSS selector) for 'click_element' in the ListTools response.{ name: 'click_element', description: 'Click a UI element identified by a CSS selector', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector to identify the element to click (e.g., "#button-id", ".button-class", "button[name=submit]")', }, }, required: ['selector'], }, },
- src/index.ts:262-271 (registration)Dispatches the 'click_element' tool call to the clickElement handler function in the CallToolRequest handler switch statement.case 'click_element': { const result = await clickElement(driver, args as any); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], };
- src/tauri-driver.ts:120-129 (helper)Low-level helper method in TauriDriver class that uses WebDriverIO to locate and click the element by CSS selector.async clickElement(selector: string): Promise<void> { this.ensureAppRunning(); const element = await this.appState.browser!.$(selector); if (!(await element.isExisting())) { throw new Error(`Element not found: ${selector}`); } await element.click(); }