Selector

An immutable description of one accessibility node.

Build one with the top-level functions (text, res, desc, ...), narrow it with the methods below and combine selectors with and / or; each call returns a new selector. Bind it with App.element for package ownership or Screen.element for whatever is visible. Mutations require exactly one match.

A Selector builds the server API's tap.v1.Selector, a small expression tree that the server forwards to the driver unchanged, so anything built here is validated identically by the server and the driver; render shows that tree, and exceptions quote it. Building a selector performs no I/O; each terminal action resolves it again.

Functions

Link copied to clipboard
infix fun and(other: Selector): Selector

Both must hold on the same node: text("Add") and clickable(). The result keeps this selector's scope and match choice; other must not carry its own match choice (first/at) or a different scope, because a node predicate cannot express either and silently dropping them would target a different element.

Link copied to clipboard
fun andClassName(value: String, mode: MatchMode = MatchMode.EXACT): Selector

Also require this widget class name.

Link copied to clipboard
fun andDesc(value: String, mode: MatchMode = MatchMode.EXACT): Selector

Also require this content description.

Link copied to clipboard
fun andHint(value: String, mode: MatchMode = MatchMode.EXACT): Selector

Also require this hint (empty text fields).

Link copied to clipboard
fun andRes(name: String): Selector

Also require the resource id name of any package (see res).

fun andRes(packageName: String, name: String): Selector

Also require the resource id packageName:id/name.

Link copied to clipboard
fun andText(value: String, mode: MatchMode = MatchMode.EXACT): Selector

Also require this text (mode: exact, contains, starts with, ends with, RE2 regex).

Link copied to clipboard
fun at(index: Int): Selector

Accept the index-th match (0-based) in accessibility order instead of requiring exactly one.

Link copied to clipboard
fun checkable(value: Boolean = true): Selector

Require isCheckable == value.

Link copied to clipboard
fun checked(value: Boolean = true): Selector

Require isChecked == value.

Link copied to clipboard
fun child(other: Selector): Selector

A direct child of this element matching other. Same rules as descendant.

Link copied to clipboard
fun clickable(value: Boolean = true): Selector

Require isClickable == value.

Link copied to clipboard

An element matching other somewhere below this one. The result keeps other's match choice and this selector's scope. This selector must not carry a match choice itself: the ancestor is a bare predicate, so list.at(2).descendant(x) would otherwise search under every list. Narrow the ancestor with predicates instead, or pick among the results (list.descendant(x).at(2)).

Link copied to clipboard
fun enabled(value: Boolean = true): Selector

Require isEnabled == value.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard

Accept the first match in accessibility order instead of requiring exactly one.

Link copied to clipboard
fun focusable(value: Boolean = true): Selector

Require isFocusable == value.

Link copied to clipboard
fun focused(value: Boolean = true): Selector

Require isFocused == value.

Link copied to clipboard

Keep matching this node, but only when an ancestor matches other.

Link copied to clipboard

Keep matching this node, but only when a direct child matches other.

Link copied to clipboard

This element must have a descendant matching other: res("card").hasDescendant(text("Play")).

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Keep matching this node, but only when its parent matches other.

Link copied to clipboard
fun longClickable(value: Boolean = true): Selector

Require isLongClickable == value.

Link copied to clipboard
infix fun or(other: Selector): Selector

Either may hold: text("Allow") or text("Allow only while using the app"). Same operand rules as and. Disjunctions are evaluated by the driver's tree walk rather than a native UiAutomator lookup, which is a little slower on big screens.

Link copied to clipboard
fun render(): String

The selector as one-line protobuf text, exactly the tree the device will see (for example node { match { property: PROPERTY_TEXT value: "OK" } }); also used in exceptions.

Link copied to clipboard
fun scrollable(value: Boolean = true): Selector

Require isScrollable == value.

Link copied to clipboard
fun selected(value: Boolean = true): Selector

Require isSelected == value.

Link copied to clipboard
open override fun toString(): String