Skip to main content

waitFor

This tool on every surface: CLI · MCP · Python · JavaScript · Go · Java · .NET

Wait until an element appears, disappears, shows particular text, or reaches a state — enabled, checked, focused, holding a value — then return. These call app_wait_for.

waitFor​

public Element waitFor(String target)
public Element waitFor(String target, WaitFor condition)

Waits for an element to be on screen, for up to ten seconds.

@param target a ref from map() such as "@e5", or a locator such as "text=Sign in" @return the element, with a fresh ref, or null when the wait was for it to go away

Blocks until the screen agrees, instead of sleeping.

On success the screen is remapped, so the element returned already has a ref that can be tapped without calling map() first. Waiting for something to go away returns null: there is nothing left to point at. If the condition never holds, the exception says what was on screen instead, which is usually the answer.

@param target a ref from map() such as "@e5", or a locator such as "text=Sign in" @param condition what to wait for, and how long @return the element, with a fresh ref, or null when the wait was for it to go away

Examples​

Wait for text to appear​

Element welcome = device.waitFor("text=Welcome back");
device.tap(welcome.ref());

Wait for a spinner to go​

device.waitFor("role=progressbar", WaitFor.hidden()); // returns null: nothing left to point at

Wait for a checkbox to be checked, for up to five seconds​

device.waitFor("testid=termsCheck", WaitFor.checked().timeout(Duration.ofSeconds(5)));

The same call from the command line, mobium wait testid=termsCheck --for checked --timeout 5s, printed on an Android 15 emulator:

testid=termsCheck is checked after 18ms — @e3 Accept terms (checkbox, checked)

On a device​

mobium wait testid=loginError --for text --text 'Incorrect username or password.' on an Android 15 emulator

mobium wait testid=loginError --for text --text 'Incorrect username or password.' on an Android 15 emulator