tap, tapAppIcon
Taps an element, or raw coordinates, on the screen.
Functions
| function | description |
|---|---|
tap(sel, holdSeconds: 0, maxGestureSeconds:containerInference:linkText:settle:waitSeconds:scroll:maxSwipes:) |
Taps the first element matching the selector. holdSeconds greater than 0 makes it a long press (default 0 = normal tap, capped at 10 seconds by default — pass maxGestureSeconds: to allow up to 60 for this one call). Waits for the target to become enabled before tapping (see Notes). Returns the tapped element, so assertions chain directly: tap("#btn_ok").textIs("OK"). |
tap(sel, linkText: "text") |
Taps the place where linkText is drawn inside the element the selector resolves to — for an inline link in a paragraph, which the accessibility tree does not expose as a node on Compose Multiplatform, Android Views (ClickableSpan) and SwiftUI (AttributedString links). Located first from the tree (a descendant whose label or value equals linkText, as Flutter and React Native expose links), then by OCR on the element's pixels. OCR is available on macOS 27+ only — on macOS 26, when the tree does not locate the text the step fails before taking a screenshot and says so. If neither finds it the step fails and lists what OCR read — it never falls back to the element's centre. The step note records which way located it (tree / ocr). On iOS the MCP tools (which run through the XCUITest bridge) may show such a link as its own element, but scenarios run in inapp-boost mode by default, where it is not — so write tap(element, linkText:) even if exploration showed the link as an element. A link wrapped across two lines is not found by OCR. Without linkText: it taps the centre of the element. |
tap(x: Double, y: Double, holdSeconds: 0, maxGestureSeconds:, settle:) |
Taps raw coordinates. Coordinates use the same system as the screen frame in a snapshot — iOS = pt, Android = px (not dp). Prefer a selector whenever one is available. A point outside the screen fails without sending anything (a negative coordinate always; the screen size is checked when the element list is read anyway). On iOS in inapp-boost mode, a point off the screen fails; a point on the software keyboard is tapped through the XCUITest bridge, so the key is pressed — to reach what is under the keyboard, close it first with pressEnter or hideKeyboard; and an element clipped out of its scroll container is not activated even if its frame contains the point — the touch is sent to whatever is actually visible at that point (the step gets the note <element> contains this point but is clipped by its scroll container here (not drawn), so it was not activated; sent a touch to what is on screen at that point). |
tap(sel, scroll: .noScroll) |
Taps without scrolling, even inside a withScrollDown { } block. |
tapAppIcon(name?) |
Taps the app icon on the home screen. For name matching and search order, see navigation. |
Example
tap("#login_btn||Log In")
tap("Settings", scroll: .down) // searches while scrolling down
tap("#row_03", holdSeconds: 1) // long press
tap("#txt_terms", linkText: "Terms of Service") // a link inside a paragraph
tap(x: 120, y: 640) // only when no selector is available
Notes
-
The next three (several matches, a covered centre, an off-list target under a cover) apply only when the tool can tell from the screen which element is drawn in front — iOS apps built with UIKit or React Native (inapp-boost mode), and Android apps built with Views or React Native.
-
When several elements match the selector: if the first one is covered by another element in front and an uncovered match exists, that one is tapped (with a note). If every match is covered and there is nowhere to press, nothing is tapped and the step fails.
-
When the target's centre is under a tab bar, fixed footer or other element in front: the list is scrolled once to clear it. If that does not clear it, the centre is not pressed (it would hit the tab in front and open another screen); the uncovered, visible part of the target is pressed instead (with a note). If that visible part is too thin (under 8pt; 8dp on Android), nothing is tapped and the step fails. Long press and
doubleTapbehave the same. -
When a target outside the list (such as a button on a top bar that hid on scroll) is under a navigation bar or similar: one scroll of the list does not bring it out, so without
scroll:nothing is tapped, the step fails and the message suggests a direction (did not touch <selector>: its centre is under <what covers it>, and touching it there would land on something else (nothing was touched). Add scroll: .up so the list is scrolled until the target comes out, with the direction that fits). Withscroll:, the list is scrolled until the target comes out from under it, then it is tapped. -
When the target is not found, and a window or modal in front has left it out of the tree: on iOS in inapp-boost mode only, the app reports when another window is in front of it, or a modal view (
accessibilityViewIsModal) is open, and the elements behind it are left out of the tree. The failure message then names that window or modal (a window in front of the app at (x,y WxH) covers N element(s), which are left out of the tree; the target may be behind it. Close that window … — waiting will not bring the target back; for a modal,a modal view (accessibilityViewIsModal) at (x,y WxH) is open and left N element group(s) out of the tree; if the target is behind it, close the modal (dismiss the dialog) first …). Do not lengthenwaitSeconds:for this: the target does not come back until the window or modal is closed. Dismiss the dialog or sheet in an earlier step, or declare it withirregularHandler. xcuitest mode and Android do not report this, and keep the usual "not found" message. -
On screens where the drawing order is not known (apps built with SwiftUI, Compose Multiplatform or Flutter, iOS in xcuitest mode, and operations from MCP), the tool does not guess which element is in front and presses the target's centre. Overlaps change with each device's screen size, so they cannot be avoided when you write the scenario. If a later step that checks the result fails and something was overlapping the target of the operation just before it, the failure message names that element and tells you how to fix the scenario: make sure the target is not covered at that step (close what covers it, or scroll the target clear of it first). Fixing it is up to you — look at the failing device's screen to decide. On iOS, the tool fails the step without pressing only when the platform answers that the target cannot be hit there; the message then tells you to close the sheet or panel in front, or to scroll the list before this step until the target is clear.
-
When the app has crashed and another app is in front: if the launched app's process is gone and the screen's tree belongs to another app, the step fails without touching or checking anything in that tree (so an element with the same
#idin another app is never operated by mistake). -
tapwaits for the target to become enabled before tapping. A screen can render an element before it is actually interactive (a form still loading, a button disabled until validation passes).tapretries resolution until the element isenabled, up to the step'swaitSeconds:(default: the run profile'sdefaultTimeout, 5 seconds unless changed). If it never becomes enabled,tapstill taps it — a scenario that deliberately taps a disabled element to assert "nothing happens" keeps working. Waiting is skipped when the selector explicitly pins the state, e.g.#btn&&enabled=false, or whenwaitSeconds: 0is given. -
Waiting for the element to appear is short: without
waitSeconds:, resolution is retried for only about 0.7 seconds until the element is found (once found,tapwaits up to thedefaultTimeout(5 seconds unless changed) for it to become enabled, as above). For an element that appears late after a screen transition, passtap("#btn", waitSeconds: 5)or wait first withwaitForDisplay("#btn"). Other operations such astypebehave the same. -
Tapping first, then typing:
tap("#field")followed bytype("some text")also works. On Android, when#idresolves to the input's wrapping container rather than the field itself, focus can fail to land in the field;typerecovers by locating the single input inside the tapped container. See type. -
Elements at the very bottom of an Android screen: on a device with gesture navigation, a touch inside the band at the bottom edge of the screen (the band that takes the home / app-switch gesture) can be taken by the OS and send the app to the background. When an element's centre lies inside this band and part of the element is above it,
tap(and long press anddoubleTap) touches the centre of the part above the band (the step gets the notetouched the part of the element above the Android bottom gesture band). An element entirely inside the band is touched at its centre. -
iOS in-app bridge: "a real touch would land elsewhere" note. The in-app bridge operates the element directly (its accessibility action, or a touch sent straight to the element's window), so it can reach an element that a real finger cannot — for example a button hidden under a keyboard accessory bar. When a real touch at the centre of the element's frame would land on another view, the step stays green and gets the note
in-app operated the element directly, but a real touch at the centre of its frame lands on another view (<view> at (x, y))(machine-readable:inapp-tap-outside-hit-area). The tap is not retried and the step is not failed. The same tap can fail on the XCUITest bridge, which presses the centre of the frame. Nothing is said when it cannot be determined (for example Flutter, which draws everything in one view). A SwiftUI.plainbutton that is tappable only on its text gets a separate note instead:in-app activated the element at its activation point, which is not the centre of its frame that a coordinate tap presses (activation point (x, y), centre (x, y))(machine-readable:inapp-activation-point-off-centre; SwiftUI and UIKit apps only). -
Coordinate taps: use them only when the app exposes nothing selectable at that spot.
Use case Guidance Writing a scenario (kept long-term) Prefer a selector. Coordinates are a last resort — they hit whatever is there once the layout moves. Ad-hoc exploration A selector is still preferred, but coordinates are fine if they resolve faster. -
A SwiftUI link may look like an element in MCP exploration but not in scenarios (inapp-boost mode). Write
tap(element, linkText:). -
Pass only the link's own text to
linkText:. If you include the surrounding words, the tap lands on the centre of that whole string, which may be outside the link, so it hits the link on some devices and misses on others (if the link is "here", pass"here", not"details here"). -
An element whose reported frame is a small box at the top-left corner of the screen is not touched; the step fails. The app's framework did not report where it is drawn, and a touch there lands on the status bar (on iOS it can switch to the previous app). Point at a neighbouring element (the row or label next to it, or a relative selector such as
:right). -
settle: falseskips the wait for the screen to settle after this one command. Normally a command waits for the screen to settle before returning (the bridge's settle wait and fleetest's comparison of the element tree after the command; each wait has an upper limit), so the next step sees the final positions. Withsettle: falsethose post-action waits are skipped for that call only, so the command returns sooner and the next step may see a screen that is still moving (positions can be off). Use it when speed matters more and the next step does not depend on final positions. Waits that verify the result (for example the typed text being read back, or the orientation actually changing) and waits before the action are kept. Commands that take it:tap(selector andx:y:),doubleTap,hold,type,clearInput,pressEnter,hideKeyboard,back,rotateTo,swipe*,flick*,scroll*,scrollTo*,pinchOut/pinchIn,gesture. It goes after the command-specific arguments and beforewaitSeconds:. The step slowdown (the wait before an action while the Mac's CPU is high) is not applied to the command either.