# By.Window

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

*** ** * ** ***


```
public class By.Window
```

<br />

*** ** * ** ***

This nested class is used to create a `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` that matches a window.

## Summary

| ### Public methods |
|---|---|
| `static @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/By.Window#active(boolean)(boolean isActive)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the active criteria. |
| `static @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/By.Window#displayId(int)(int displayId)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the display ID criteria. |
| `static @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/By.Window#focused(boolean)(boolean isFocused)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the focused criteria. |
| `static @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/By.Window#id(int)(int id)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the window id criteria. |
| `static @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/By.Window#layer(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int layer)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the layer (Z-order) criteria. |
| `static @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/By.Window#layerAbove(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int referenceLayer)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the layer (Z-order) criteria. |
| `static @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/By.Window#layerBelow(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int referenceLayer)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the layer (Z-order) criteria. |
| `static @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/By.Window#pkg(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the package criteria. |
| `static @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/By.Window#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 regex)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the package criteria. |
| `static @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/By.Window#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 regex)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the title criteria. |
| `static @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/By.Window#title(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html title)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the title criteria. |
| `static @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/By.Window#titleContains(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html substring)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the title criteria. |
| `static @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/By.Window#titleEndsWith(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html suffix)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the title criteria. |
| `static @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/By.Window#titleStartsWith(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html prefix)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the title criteria. |
| `static @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/By.Window#type(int)(int type)` Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the type criteria. |

## Public methods

### active

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the active criteria.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#active(boolean)` | ByWindowSelector.active(boolean) |

### displayId

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

```
@RequiresApi(value = 30)
public static @NonNull ByWindowSelector displayId(int displayId)
```

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the display ID criteria.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#displayId(int)` | ByWindowSelector.displayId(int) |

### focused

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the focused criteria.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#focused(boolean)` | ByWindowSelector.focused(boolean) |

### id

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the window id criteria.

The window id can be obtained from `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#getId()`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#id(int)` | ByWindowSelector.id(int) |

### layer

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the layer (Z-order) criteria.

The layer ID can be obtained from `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#getLayer()`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#layer(int)` | ByWindowSelector.layer(int) |

### layerAbove

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the layer (Z-order) criteria.

The referenced layer ID can be obtained from `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#getLayer()`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#layerAbove(int)` | ByWindowSelector.layerAbove(int) |

### layerBelow

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the layer (Z-order) criteria.

The referenced layer ID can be obtained from `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#getLayer()`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#layerBelow(int)` | ByWindowSelector.layerBelow(int) |

### pkg

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the package criteria.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#pkg(java.lang.String)` | ByWindowSelector.pkg(String) |

### pkg

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

```
public static @NonNull ByWindowSelector pkg(@NonNull Pattern regex)
```

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the package criteria.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#pkg(java.util.regex.Pattern)` | ByWindowSelector.pkg(Pattern) |

### title

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the title criteria.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#title(java.util.regex.Pattern)` | ByWindowSelector.title(Pattern) |

### title

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the title criteria.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#title(java.lang.String)` | ByWindowSelector.title(String) |

### titleContains

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the title criteria.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#titleContains(java.lang.String)` | ByWindowSelector.titleContains(String) |

### titleEndsWith

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the title criteria.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#titleEndsWith(java.lang.String)` | ByWindowSelector.titleEndsWith(String) |

### titleStartsWith

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the title criteria.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#titleStartsWith(java.lang.String)` | ByWindowSelector.titleStartsWith(String) |

### type

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

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

Constructs a new `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector` and sets the type criteria.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/ByWindowSelector#type(int)` | ByWindowSelector.type(int) |