Skip to main content
A locator describes a target: visible text, or a plain-language description. Create one with driver.get_by_text() or driver.locator(). Building a locator sends nothing. Each action finds the target on the screen at that moment, waits until it can act, then acts, all in one round trip.
Plain text resolves by OCR. A description, or a refinement such as nth or has, resolves with one vision-model call. Every action waits up to 5 seconds by default; pass timeout in seconds, up to 60. When the target never becomes ready, the call raises ActionTimeoutError, which is also a built-in TimeoutError. The Go names are in the map at the end.

Actions

locator.tap()

Wait for the target, then tap its center.
Returns LocatorResult.

locator.fill()

Wait for the target, tap it to focus, then type text.
Returns LocatorResult.

locator.press()

Wait for the target, focus it, then press a named key.
Returns LocatorResult.

locator.wait_for()

Wait until the target is visible, or until it is gone, without acting on it.
Returns LocatorResult, or None for state="hidden".

Queries

locator.text()

Wait for the target, then return its recognized text.
Returns str.

locator.count()

Count the matches on the screen right now, zero included. This is the one call that never waits. It needs a plain text locator: one with a description, within, or has raises InvalidArgsError.
Returns int.

locator.bounding_box()

Wait for the target, then return where it is. Use it for gestures a locator doesn’t have, such as a long-press or a drag.
Returns LocatorResult with bounds set. A target found by a description can come back as a small box or a single point; its center is still where to act.

Refinements

Each refinement returns a new locator and keeps the OCR engine and model of the one it refines.

locator.nth()

The nth match in reading order, counting from zero.
Returns Locator.

locator.first()

The first match in reading order. Shorthand for nth(0). Returns Locator.

locator.within()

A match that is inside another locator’s target.
Returns Locator.

locator.has()

A match that contains another locator’s target.
Returns Locator.

locator.filter()

Add a description on top of the locator’s text.
Returns Locator.

LocatorResult

What an action or query reports about the target it resolved.

Go method map

Go builds locators with driver.GetByText(text, opts...) and driver.Locator(opts...), using the options mobile.Text, mobile.Query, mobile.Exact, mobile.Model, and mobile.OCREngine. Actions take mobile.WithTimeout(d). A Go timeout is reported by mobile.IsActionTimeout(err). Locator actions use the DCP Locator.* methods; they are not REST operations.

See also

Find

Choose between text and a description.

Driver

Create locators and run coordinate actions.