ui.wait_for
Wait for UI elements to appear or become visible in iOS Simulator during React Native/Expo testing, ensuring reliable automation by specifying selectors and timeout settings.
Instructions
Wait for an element to be visible or exist
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | Element selector to wait for. | |
| visible | No | Wait for visibility (true) or existence (false). | |
| timeout | No | Timeout in milliseconds. |
Implementation Reference
- src/mcp/server.ts:624-653 (handler)Primary handler for the 'ui.wait_for' MCP tool. Generates a Detox snippet using generateWaitForSnippet and executes it with runDetoxAction, returning the result in MCP format.server.tool( "ui.wait_for", "Wait for an element to be visible or exist", UiWaitForInputSchema.shape, async (args) => { try { const snippet = generateWaitForSnippet({ selector: args.selector, visible: args.visible, timeout: args.timeout, }); const result = await runDetoxAction({ actionName: `waitFor:${describeSelector(args.selector)}`, actionSnippet: snippet, timeoutMs: (args.timeout ?? 30000) + 5000, // Add buffer }); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; } catch (error) { return handleToolError(error); } } );
- src/mcp/schemas.ts:86-90 (schema)Input schema (Zod) for the ui.wait_for tool, defining selector, visible flag, and timeout.export const UiWaitForInputSchema = z.object({ selector: SelectorSchema.describe("Element selector to wait for."), visible: z.boolean().optional().default(true).describe("Wait for visibility (true) or existence (false)."), timeout: z.number().optional().default(30000).describe("Timeout in milliseconds."), });
- src/mcp/server.ts:738-748 (helper)Internal helper implementation of ui.wait_for logic used by the flow.run tool executor.case "ui.wait_for": const waitSnippet = generateWaitForSnippet({ selector: input.selector as { by: "id" | "text" | "label"; value: string }, visible: input.visible as boolean | undefined, timeout: input.timeout as number | undefined, }); const waitResult = await runDetoxAction({ actionName: `waitFor:${(input.selector as { value: string }).value}`, actionSnippet: waitSnippet, }); return { success: waitResult.success, result: waitResult, error: waitResult.error?.message };
- src/detox/actions.ts:112-120 (helper)Helper function that generates the actual Detox JavaScript code snippet for waiting on an element (visible or exists). This is the core UI waiting logic.export function generateWaitForSnippet(options: WaitForOptions): string { const matcher = selectorToDetoxExpr(options.selector); const timeout = options.timeout ?? 30000; if (options.visible !== false) { return `await waitFor(element(${matcher})).toBeVisible().withTimeout(${timeout});`; } return `await waitFor(element(${matcher})).toExist().withTimeout(${timeout});`; }