waitFor

fun UiDevice.waitFor(selector: BySelector, timeoutMs: Long = DEFAULT_WAIT_FOR_TIMEOUT_MS): UiObject2

Helper method to wait for a given selector to be found.

Tries to find an object for the selector periodically until the timeout specified by timeoutMs expires. When no object matches within the given timeoutMs, an IllegalStateException is thrown.