# UiSelector

# UiSelector

Artifact:[androidx.test.uiautomator:uiautomator](https://developer.android.com/jetpack/androidx/releases/test-uiautomator)  
[View Source](https://cs.android.com/search?q=file:androidx/test/uiautomator/UiSelector.java+class:androidx.test.uiautomator.UiSelector)  
Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/test/uiautomator/UiSelector "View this page in Java")

<br />

```
class UiSelector
```

<br />

*** ** * ** ***

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                                               |
|--------------------------------------------------------------------------------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#UiSelector())`()` |

|                                       ### Public functions                                        |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [checkable](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#checkable(boolean))`(val: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Set the search criteria to match widgets that are checkable.                                                                                              |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [checked](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#checked(boolean))`(val: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Set the search criteria to match widgets that are currently checked (usually for checkboxes).                                                                 |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [childSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#childSelector(androidx.test.uiautomator.UiSelector))`(selector: `[UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector)`)` Adds a child UiSelector criteria to this selector.                                                |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [className](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#className(java.lang.String))`(className: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match the class property for a widget (for example, "android.widget.Button").                                     |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | `<T> `[className](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#className(java.lang.Class<T>))`(type: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>)` Set the search criteria to match the class property for a widget (for example, "android.widget.Button").                                          |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [classNameMatches](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#classNameMatches(java.lang.String))`(regex: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match the class property for a widget, using a regular expression.                                      |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [clickable](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#clickable(boolean))`(val: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Set the search criteria to match widgets that are clickable.                                                                                              |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [description](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#description(java.lang.String))`(desc: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match the content-description property for a widget.                                                               |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [descriptionContains](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#descriptionContains(java.lang.String))`(desc: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match the content-description property for a widget.                                               |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [descriptionMatches](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#descriptionMatches(java.lang.String))`(regex: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match the content-description property for a widget.                                                |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [descriptionStartsWith](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#descriptionStartsWith(java.lang.String))`(desc: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match the content-description property for a widget.                                           |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [enabled](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#enabled(boolean))`(val: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Set the search criteria to match widgets that are enabled.                                                                                                    |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [focusable](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#focusable(boolean))`(val: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Set the search criteria to match widgets that are focusable.                                                                                              |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [focused](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#focused(boolean))`(val: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Set the search criteria to match widgets that have focus.                                                                                                     |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [fromParent](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#fromParent(androidx.test.uiautomator.UiSelector))`(selector: `[UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector)`)` Adds a child UiSelector criteria to this selector which is used to start search from the parent widget. |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [index](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#index(int))`(index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Set the search criteria to match the widget by its node index in the layout hierarchy.                                                                                      |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [instance](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#instance(int))`(instance: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Set the search criteria to match the widget by its instance number.                                                                                                |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [longClickable](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#longClickable(boolean))`(val: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Set the search criteria to match widgets that are long-clickable.                                                                                 |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [packageName](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#packageName(java.lang.String))`(name: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match the package name of the application that contains the widget.                                                |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [packageNameMatches](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#packageNameMatches(java.lang.String))`(regex: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match the package name of the application that contains the widget.                                 |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [resourceId](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#resourceId(java.lang.String))`(id: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match the given resource ID.                                                                                           |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [resourceIdMatches](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#resourceIdMatches(java.lang.String))`(regex: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match the resource ID of the widget, using a regular expression.                                      |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [scrollable](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#scrollable(boolean))`(val: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Set the search criteria to match widgets that are scrollable.                                                                                           |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [selected](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#selected(boolean))`(val: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Set the search criteria to match widgets that are currently selected.                                                                                       |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [text](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#text(java.lang.String))`(text: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match the visible text displayed in a widget (for example, the text label to launch an app).                                     |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [textContains](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#textContains(java.lang.String))`(text: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` 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](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [textMatches](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#textMatches(java.lang.String))`(regex: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match the visible text displayed in a layout element, using a regular expression.                                 |
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [textStartsWith](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#textStartsWith(java.lang.String))`(text: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Set the search criteria to match visible text in a widget that is prefixed by the text parameter.                                       |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`              | [toString](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#toString())`()`                                                                                                                                                                                                                                                              |

|                                      ### Protected functions                                      |
|---------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | [cloneSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#cloneSelector())`()` |

## Public constructors

### UiSelector

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
UiSelector()
```  

## Public functions

### checkable

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### checked

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### childSelector

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) |   |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|---------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with this added search criterion |

### className

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### className

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://developer.android.com/reference/java/lang/Class.html)`<T!>` | type |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### classNameMatches

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
fun classNameMatches(regex: String): UiSelector
```

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

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|----------------------|
| `regex: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | a regular expression |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### clickable

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### description

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### descriptionContains

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### descriptionMatches

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | a regular expression |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### descriptionStartsWith

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### enabled

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### focusable

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### focused

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### fromParent

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) |   |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|---------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with this added search criterion |

### index

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#instance(int))method.  

|                                      Parameters                                      |
|--------------------------------------------------------------------------------------|----------------|
| `index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### instance

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#className(java.lang.String))matches the image widget class, and[enabled](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector#enabled(boolean))is true. The code would look like this:`
new UiSelector().className("android.widget.ImageView")
.enabled(true).instance(2);
`  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|----------------|
| `instance: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### longClickable

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### packageName

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
fun packageName(name: String): UiSelector
```

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

|                                        Parameters                                         |
|-------------------------------------------------------------------------------------------|----------------|
| `name: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### packageNameMatches

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
fun packageNameMatches(regex: String): UiSelector
```

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

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|----------------------|
| `regex: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | a regular expression |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### resourceId

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
fun resourceId(id: String): UiSelector
```

Set the search criteria to match the given resource ID.  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|----------------|
| `id: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### resourceIdMatches

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
fun resourceIdMatches(regex: String): UiSelector
```

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

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|----------------------|
| `regex: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | a regular expression |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### scrollable

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### selected

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### text

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### textContains

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### textMatches

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | a regular expression |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### textStartsWith

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | Value to match |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [UiSelector](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector) | UiSelector with the specified search criteria |

### toString

```
fun toString(): String!
```  

## Protected functions

### cloneSelector

Added in[2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)  

```
protected fun cloneSelector(): UiSelector
```