wait_for_element
Waits for a UI element to appear in the DOM using CSS selectors, handling asynchronous page loading and dynamic content changes during automated testing.
Instructions
Wait for an element to appear in the DOM. Useful for handling async UI states.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector to wait for | |
| timeout | No | Timeout in milliseconds. Default: 5000 |
Implementation Reference
- src/tools/interact.ts:59-77 (handler)The primary tool handler function that executes the wait_for_element tool logic. It calls the TauriDriver's waitForElement method and returns a standardized ToolResponse.export async function waitForElement( driver: TauriDriver, params: WaitForElementParams ): Promise<ToolResponse<{ message: string }>> { try { await driver.waitForElement(params.selector, params.timeout); return { success: true, data: { message: `Element found: ${params.selector}`, }, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error), }; }
- src/index.ts:139-157 (registration)Tool registration in the ListTools response, defining name, description, and input schema.{ name: 'wait_for_element', description: 'Wait for an element to appear in the DOM. Useful for handling async UI states.', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector to wait for', }, timeout: { type: 'number', description: 'Timeout in milliseconds. Default: 5000', default: 5000, }, }, required: ['selector'], }, },
- src/types.ts:84-89 (schema)TypeScript interface defining the input parameters for wait_for_element.export interface WaitForElementParams { /** CSS selector to wait for */ selector: string; /** Timeout in milliseconds */ timeout?: number; }
- src/tauri-driver.ts:152-162 (helper)Core implementation in TauriDriver class using WebDriverIO to wait for the element to exist.async waitForElement(selector: string, timeout?: number): Promise<void> { this.ensureAppRunning(); const waitTimeout = timeout || this.config.defaultTimeout; const element = await this.appState.browser!.$(selector); await element.waitForExist({ timeout: waitTimeout, timeoutMsg: `Element not found within ${waitTimeout}ms: ${selector}`, }); }
- src/index.ts:286-295 (handler)MCP server dispatcher case that invokes the waitForElement handler from interact.ts.case 'wait_for_element': { const result = await waitForElement(driver, args as any); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], };