# 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)

*** ** * ** ***


```
public class ByWindowSelector
```

<br />

*** ** * ** ***

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

## Summary

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

## Public methods

### active

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

```
public @NonNull ByWindowSelector active(boolean isActive)
```

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

| Parameters |
|---|---|
| `boolean isActive` | Whether to match windows that are active or inactive. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/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)
public @NonNull ByWindowSelector displayId(int displayId)
```

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 |
|---|---|
| `int displayId` | The display ID to match. Use Display#getDisplayId() to get the ID. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### focused

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

```
public @NonNull ByWindowSelector focused(boolean isFocused)
```

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

| Parameters |
|---|---|
| `boolean isFocused` | Whether to match windows that are focused or not. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### id

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

```
public @NonNull ByWindowSelector id(int id)
```

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 |
|---|---|
| `int id` | The id to match. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### layer

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

```
public @NonNull ByWindowSelector layer(@IntRange(from = 0) int exactLayer)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int exactLayer` | The layer to match. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### layerAbove

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

```
public @NonNull ByWindowSelector layerAbove(@IntRange(from = 0) int referenceLayer)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int referenceLayer` | The layer which matching windows must be above. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### layerBelow

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

```
public @NonNull ByWindowSelector layerBelow(@IntRange(from = 1) int referenceLayer)
```

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

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

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### pkg

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

```
public @NonNull ByWindowSelector pkg(@NonNull Pattern packageName)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html packageName` | The `https://developer.android.com/reference/java/util/regex/Pattern.html` to be used for window matching. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### pkg

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

```
public @NonNull ByWindowSelector pkg(@NonNull String packageName)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName` | The exact package name to match (case-sensitive). e.g. "com.example .android" |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### title

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

```
public @NonNull ByWindowSelector title(@NonNull Pattern title)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html title` | The `https://developer.android.com/reference/java/util/regex/Pattern.html` to be used for window matching. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### title

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

```
public @NonNull ByWindowSelector title(@NonNull String title)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html title` | The exact value to match (case-sensitive). |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### titleContains

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

```
public @NonNull ByWindowSelector titleContains(@NonNull String substring)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html substring` | The substring to match (case-sensitive). |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### titleEndsWith

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

```
public @NonNull ByWindowSelector titleEndsWith(@NonNull String suffix)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html suffix` | The suffix to match (case-sensitive). |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### titleStartsWith

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

```
public @NonNull ByWindowSelector titleStartsWith(@NonNull String prefix)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html prefix` | The prefix to match (case-sensitive). |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |

### toString

```
public @NonNull String toString()
```

Returns a `https://developer.android.com/reference/java/lang/String.html` representation of this `https://developer.android.com/reference/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)

```
public @NonNull ByWindowSelector type(int type)
```

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 |
|---|---|
| `int type` | The exact type to match (e.g. `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#TYPE_APPLICATION`). |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` | A reference to this `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector`. |