class UiSelector


Specifies the elements in the layout hierarchy for tests to target, filtered by properties such as text value, content-description, class name, and state information. You can also target an element by its location in a layout hierarchy.

Summary

Public constructors

Public functions

UiSelector

Set the search criteria to match widgets that are checkable.

UiSelector

Set the search criteria to match widgets that are currently checked (usually for checkboxes).

UiSelector

Adds a child UiSelector criteria to this selector.

UiSelector
className(className: String)

Set the search criteria to match the class property for a widget (for example, "android.widget.Button").

UiSelector
<T> className(type: Class<T!>)

Set the search criteria to match the class property for a widget (for example, "android.widget.Button").

UiSelector

Set the search criteria to match the class property for a widget, using a regular expression.

UiSelector

Set the search criteria to match widgets that are clickable.

UiSelector

Set the search criteria to match the content-description property for a widget.

UiSelector

Set the search criteria to match the content-description property for a widget.

UiSelector

Set the search criteria to match the content-description property for a widget.

UiSelector

Set the search criteria to match the content-description property for a widget.

UiSelector

Set the search criteria to match widgets that are enabled.

UiSelector

Set the search criteria to match widgets that are focusable.

UiSelector

Set the search criteria to match widgets that have focus.

UiSelector

Adds a child UiSelector criteria to this selector which is used to start search from the parent widget.

UiSelector
index(index: Int)

Set the search criteria to match the widget by its node index in the layout hierarchy.

UiSelector
instance(instance: Int)

Set the search criteria to match the widget by its instance number.

UiSelector

Set the search criteria to match widgets that are long-clickable.

UiSelector

Set the search criteria to match the package name of the application that contains the widget.

UiSelector

Set the search criteria to match the package name of the application that contains the widget.

UiSelector

Set the search criteria to match the given resource ID.

UiSelector

Set the search criteria to match the resource ID of the widget, using a regular expression.

UiSelector

Set the search criteria to match widgets that are scrollable.

UiSelector

Set the search criteria to match widgets that are currently selected.

UiSelector
text(text: String)

Set the search criteria to match the visible text displayed in a widget (for example, the text label to launch an app).

UiSelector

Set the search criteria to match the visible text in a widget where the visible text must contain the string in your input argument.

UiSelector

Set the search criteria to match the visible text displayed in a layout element, using a regular expression.

UiSelector

Set the search criteria to match visible text in a widget that is prefixed by the text parameter.

String!

Protected functions

UiSelector

Public constructors

UiSelector

UiSelector()

Public functions

checkable

fun checkable(val: Boolean): UiSelector

Set the search criteria to match widgets that are checkable. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

Parameters
val: Boolean

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

checked

fun checked(val: Boolean): UiSelector

Set the search criteria to match widgets that are currently checked (usually for checkboxes). Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

Parameters
val: Boolean

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

childSelector

fun childSelector(selector: UiSelector): UiSelector

Adds a child UiSelector criteria to this selector. Use this selector to narrow the search scope to child widgets under a specific parent widget.

Parameters
selector: UiSelector
Returns
UiSelector

UiSelector with this added search criterion

className

fun className(className: String): UiSelector

Set the search criteria to match the class property for a widget (for example, "android.widget.Button").

Parameters
className: String

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

className

fun <T> className(type: Class<T!>): UiSelector

Set the search criteria to match the class property for a widget (for example, "android.widget.Button").

Parameters
type: Class<T!>

type

Returns
UiSelector

UiSelector with the specified search criteria

classNameMatches

fun classNameMatches(regex: String): UiSelector

Set the search criteria to match the class property for a widget, using a regular expression.

Parameters
regex: String

a regular expression

Returns
UiSelector

UiSelector with the specified search criteria

clickable

fun clickable(val: Boolean): UiSelector

Set the search criteria to match widgets that are clickable. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

Parameters
val: Boolean

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

description

fun description(desc: String): UiSelector

Set the search criteria to match the content-description property for a widget. The content-description is typically used by the Android Accessibility framework to provide an audio prompt for the widget when the widget is selected. The content-description for the widget must match exactly with the string in your input argument. Matching is case-sensitive.

Parameters
desc: String

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

descriptionContains

fun descriptionContains(desc: String): UiSelector

Set the search criteria to match the content-description property for a widget. The content-description is typically used by the Android Accessibility framework to provide an audio prompt for the widget when the widget is selected. The content-description for the widget must contain the string in your input argument. Matching is case-insensitive.

Parameters
desc: String

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

descriptionMatches

fun descriptionMatches(regex: String): UiSelector

Set the search criteria to match the content-description property for a widget. The content-description is typically used by the Android Accessibility framework to provide an audio prompt for the widget when the widget is selected. The content-description for the widget must match exactly with the string in your input argument.

Parameters
regex: String

a regular expression

Returns
UiSelector

UiSelector with the specified search criteria

descriptionStartsWith

fun descriptionStartsWith(desc: String): UiSelector

Set the search criteria to match the content-description property for a widget. The content-description is typically used by the Android Accessibility framework to provide an audio prompt for the widget when the widget is selected. The content-description for the widget must start with the string in your input argument. Matching is case-insensitive.

Parameters
desc: String

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

enabled

fun enabled(val: Boolean): UiSelector

Set the search criteria to match widgets that are enabled. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

Parameters
val: Boolean

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

focusable

fun focusable(val: Boolean): UiSelector

Set the search criteria to match widgets that are focusable. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

Parameters
val: Boolean

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

focused

fun focused(val: Boolean): UiSelector

Set the search criteria to match widgets that have focus. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

Parameters
val: Boolean

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

fromParent

fun fromParent(selector: UiSelector): UiSelector

Adds a child UiSelector criteria to this selector which is used to start search from the parent widget. Use this selector to narrow the search scope to sibling widgets as well all child widgets under a parent.

Parameters
selector: UiSelector
Returns
UiSelector

UiSelector with this added search criterion

index

fun index(index: Int): UiSelector

Set the search criteria to match the widget by its node index in the layout hierarchy. The index value must be 0 or greater. Using the index can be unreliable and should only be used as a last resort for matching. Instead, consider using the instance method.

Parameters
index: Int

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

instance

fun instance(instance: Int): UiSelector

Set the search criteria to match the widget by its instance number. The instance value must be 0 or greater, where the first instance is 0. For example, to simulate a user click on the third image that is enabled in a UI screen, you could specify a a search criteria where the instance is 2, the className matches the image widget class, and enabled is true. The code would look like this: new UiSelector().className("android.widget.ImageView") .enabled(true).instance(2);

Parameters
instance: Int

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

longClickable

fun longClickable(val: Boolean): UiSelector

Set the search criteria to match widgets that are long-clickable. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

Parameters
val: Boolean

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

packageName

fun packageName(name: String): UiSelector

Set the search criteria to match the package name of the application that contains the widget.

Parameters
name: String

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

packageNameMatches

fun packageNameMatches(regex: String): UiSelector

Set the search criteria to match the package name of the application that contains the widget.

Parameters
regex: String

a regular expression

Returns
UiSelector

UiSelector with the specified search criteria

resourceId

fun resourceId(id: String): UiSelector

Set the search criteria to match the given resource ID.

Parameters
id: String

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

resourceIdMatches

fun resourceIdMatches(regex: String): UiSelector

Set the search criteria to match the resource ID of the widget, using a regular expression.

Parameters
regex: String

a regular expression

Returns
UiSelector

UiSelector with the specified search criteria

scrollable

fun scrollable(val: Boolean): UiSelector

Set the search criteria to match widgets that are scrollable. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

Parameters
val: Boolean

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

selected

fun selected(val: Boolean): UiSelector

Set the search criteria to match widgets that are currently selected. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

Parameters
val: Boolean

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

text

fun text(text: String): UiSelector

Set the search criteria to match the visible text displayed in a widget (for example, the text label to launch an app). The text for the element must match exactly with the string in your input argument. Matching is case-sensitive.

Parameters
text: String

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

textContains

fun textContains(text: String): UiSelector

Set the search criteria to match the visible text in a widget where the visible text must contain the string in your input argument. The matching is case-sensitive.

Parameters
text: String

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

textMatches

fun textMatches(regex: String): UiSelector

Set the search criteria to match the visible text displayed in a layout element, using a regular expression. The text in the widget must match exactly with the string in your input argument.

Parameters
regex: String

a regular expression

Returns
UiSelector

UiSelector with the specified search criteria

textStartsWith

fun textStartsWith(text: String): UiSelector

Set the search criteria to match visible text in a widget that is prefixed by the text parameter. The matching is case-insensitive.

Parameters
text: String

Value to match

Returns
UiSelector

UiSelector with the specified search criteria

toString

fun toString(): String!

Protected functions

cloneSelector

protected fun cloneSelector(): UiSelector