# ByWindowSelector

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/ByWindowSelector.java+class:androidx.test.uiautomator.ByWindowSelector) Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

*** ** * ** ***


```
class ByWindowSelector
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` specifies criteria for matching UI windows during a call to `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#findWindow(androidx.test.uiautomator.ByWindowSelector)`.

## Summary

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#active(boolean)(isActive: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets the search criteria to match windows that are active or inactive. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 30) https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#displayId(int)(displayId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Adds a display ID selector criteria for matching. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#focused(boolean)(isFocused: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets the search criteria to match windows that are focused or not. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#id(int)(id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the id criteria for matching. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#layer(int)(exactLayer: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the layer (Z-order) criteria for matching. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#layerAbove(int)(referenceLayer: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the layer (Z-order) criteria for finding windows that are layered above the specified reference layer. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#layerBelow(int)(referenceLayer: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the layer (Z-order) criteria for finding windows that are layered below the specified reference layer. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#pkg(java.util.regex.Pattern)(packageName: https://developer.android.com/reference/java/util/regex/Pattern.html)` Sets the package name criteria for window matching. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#pkg(java.lang.String)(packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Sets the package name criteria for window matching. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#title(java.util.regex.Pattern)(title: https://developer.android.com/reference/java/util/regex/Pattern.html)` Sets the title criteria for matching. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#title(java.lang.String)(title: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Sets the title criteria for matching. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#titleContains(java.lang.String)(substring: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Sets the title criteria for matching. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#titleEndsWith(java.lang.String)(suffix: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Sets the title criteria for matching. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#titleStartsWith(java.lang.String)(prefix: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Sets the title criteria for matching. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#toString()()` Returns a `https://developer.android.com/reference/java/lang/String.html` representation of this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector#type(int)(type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the type criteria for window matching. |

## Public functions

### active

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

```
fun active(isActive: Boolean): ByWindowSelector
```

Sets the search criteria to match windows that are active or inactive.

| Parameters |
|---|---|
| `isActive: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether to match windows that are active or inactive. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### displayId

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

```
@RequiresApi(value = 30)
fun displayId(displayId: Int): ByWindowSelector
```

Adds a display ID selector criteria for matching. A UI element will be considered a match if it is within the display with the ID of `displayId` and all other criteria for this selector are met.

| Parameters |
|---|---|
| `displayId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The display ID to match. Use Display#getDisplayId() to get the ID. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### focused

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

```
fun focused(isFocused: Boolean): ByWindowSelector
```

Sets the search criteria to match windows that are focused or not.

| Parameters |
|---|---|
| `isFocused: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether to match windows that are focused or not. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### id

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

```
fun id(id: Int): ByWindowSelector
```

Sets the id criteria for matching. A UI window will be considered a match if its id matches the `id` parameter and all other criteria for this selector are met.

| Parameters |
|---|---|
| `id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The id to match. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### layer

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

```
fun layer(exactLayer: @IntRange(from = 0) Int): ByWindowSelector
```

Sets the layer (Z-order) criteria for matching. A UI window will be considered a match if its layer matches the `layer` parameter and all other criteria for this selector are met.

| Parameters |
|---|---|
| `exactLayer: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The layer to match. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### layerAbove

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

```
fun layerAbove(referenceLayer: @IntRange(from = 0) Int): ByWindowSelector
```

Sets the layer (Z-order) criteria for finding windows that are layered above the specified reference layer.

| Parameters |
|---|---|
| `referenceLayer: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The layer which matching windows must be above. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### layerBelow

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

```
fun layerBelow(referenceLayer: @IntRange(from = 1) Int): ByWindowSelector
```

Sets the layer (Z-order) criteria for finding windows that are layered below the specified reference layer.

| Parameters |
|---|---|
| `referenceLayer: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The layer which matching windows must be below. must be positive. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### pkg

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

```
fun pkg(packageName: Pattern): ByWindowSelector
```

Sets the package name criteria for window matching. A UI window will be considered a match if its package name exactly matches the `packageName` and all other criteria for this selector are met.

| Parameters |
|---|---|
| `packageName: https://developer.android.com/reference/java/util/regex/Pattern.html` | The `https://developer.android.com/reference/java/util/regex/Pattern.html` to be used for window matching. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### pkg

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

```
fun pkg(packageName: String): ByWindowSelector
```

Sets the package name criteria for window matching. A UI window will be considered a match if its package name exactly matches the `packageName` and all other criteria for this selector are met.

| Parameters |
|---|---|
| `packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The exact package name to match (case-sensitive). e.g. "com.example .android" |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### title

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

```
fun title(title: Pattern): ByWindowSelector
```

Sets the title criteria for matching. A UI window will be considered a match if its title matches the `title``https://developer.android.com/reference/java/util/regex/Pattern.html` and all other criteria for this selector are met.

| Parameters |
|---|---|
| `title: https://developer.android.com/reference/java/util/regex/Pattern.html` | The `https://developer.android.com/reference/java/util/regex/Pattern.html` to be used for window matching. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### title

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

```
fun title(title: String): ByWindowSelector
```

Sets the title criteria for matching. A UI window will be considered a match if its title exactly matches the `title` parameter and all other criteria for this selector are met.

| Parameters |
|---|---|
| `title: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The exact value to match (case-sensitive). |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### titleContains

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

```
fun titleContains(substring: String): ByWindowSelector
```

Sets the title criteria for matching. A UI window will be considered a match if its title contains the `substring` and all other criteria for this selector are met.

| Parameters |
|---|---|
| `substring: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The substring to match (case-sensitive). |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### titleEndsWith

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

```
fun titleEndsWith(suffix: String): ByWindowSelector
```

Sets the title criteria for matching. A UI window will be considered a match if its title ends with the `suffix` and all other criteria for this selector are met.

| Parameters |
|---|---|
| `suffix: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The suffix to match (case-sensitive). |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### titleStartsWith

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

```
fun titleStartsWith(prefix: String): ByWindowSelector
```

Sets the title criteria for matching. A UI window will be considered a match if its title starts with the `prefix` and all other criteria for this selector are met.

| Parameters |
|---|---|
| `prefix: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The prefix to match (case-sensitive). |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |

### toString

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

Returns a `https://developer.android.com/reference/java/lang/String.html` representation of this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. The format is "ByWindowSelector \[='', ... \]". Each criteria is listed as a key-value pair where the key is the name of the criteria expressed in all caps (e.g. TYPE, TITLE, etc).

### type

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

```
fun type(type: Int): ByWindowSelector
```

Sets the type criteria for window matching. A UI window will be considered a match if its type exactly matches the `type` and all other criteria for this selector are met.

| Parameters |
|---|---|
| `type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The exact type to match (e.g. `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#TYPE_APPLICATION`). |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector`. |