Skip to main content
Glama
Radek44
by Radek44

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
NameRequiredDescriptionDefault
selectorYesCSS selector to wait for
timeoutNoTimeout in milliseconds. Default: 5000

Implementation Reference

  • 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'], }, },
  • 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; }
  • 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}`, }); }
  • 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), }, ], };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Radek44/mcp-tauri-automation'

If you have feedback or need assistance with the MCP directory API, please join our Discord server