ui.tap
Tap on iOS Simulator UI elements using selectors like ID, text, or label to automate testing and interactions in React Native/Expo applications.
Instructions
Tap on an element identified by selector
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | Element selector. | |
| x | No | X offset from element center. | |
| y | No | Y offset from element center. |
Implementation Reference
- src/mcp/server.ts:448-476 (handler)Primary MCP tool registration and handler for 'ui.tap': parses args, generates Detox action snippet using generateTapSnippet, executes via runDetoxAction, handles errors, and returns formatted result.server.tool( "ui.tap", "Tap on an element identified by selector", UiTapInputSchema.shape, async (args) => { try { const snippet = generateTapSnippet({ selector: args.selector, x: args.x, y: args.y, }); const result = await runDetoxAction({ actionName: `tap:${describeSelector(args.selector)}`, actionSnippet: snippet, }); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; } catch (error) { return handleToolError(error); } } );
- src/mcp/schemas.ts:52-56 (schema)Zod input schema for ui.tap tool, referencing shared SelectorSchema for element identification.export const UiTapInputSchema = z.object({ selector: SelectorSchema.describe("Element selector."), x: z.number().optional().describe("X offset from element center."), y: z.number().optional().describe("Y offset from element center."), });
- src/detox/actions.ts:15-21 (helper)Core helper function that generates the Detox JavaScript snippet for the tap action based on selector and optional coordinates.export function generateTapSnippet(options: TapOptions): string { const el = buildElementExpr(options.selector); if (options.x !== undefined && options.y !== undefined) { return `await ${el}.tap({ x: ${options.x}, y: ${options.y} });`; } return `await ${el}.tap();`; }
- src/detox/selectors.ts:30-36 (helper)Selector helpers: buildElementExpr constructs Detox element matcher string used in tap snippet; selectorToDetoxExpr maps MCP selector to Detox by.id/text/label.export function buildElementExpr(selector: Selector, index?: number): string { const matcher = selectorToDetoxExpr(selector); if (index !== undefined) { return `element(${matcher}).atIndex(${index})`; } return `element(${matcher})`; }
- src/mcp/server.ts:714-724 (helper)Internal ui.tap handler implementation within the flow.run tool executor (ToolExecutor).case "ui.tap": const tapSnippet = generateTapSnippet({ selector: input.selector as { by: "id" | "text" | "label"; value: string }, x: input.x as number | undefined, y: input.y as number | undefined, }); const tapResult = await runDetoxAction({ actionName: `tap:${(input.selector as { value: string }).value}`, actionSnippet: tapSnippet, }); return { success: tapResult.success, result: tapResult, error: tapResult.error?.message };