# UiWindow

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

*** ** * ** ***


```
public final class UiWindow implements Searchable
```

<br />

*** ** * ** ***

Represents a UI window on the screen and provides methods to access its properties and perform actions.

Similar to `https://developer.android.com/reference/androidx/test/uiautomator/UiObject2` that wraps `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html`, a `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow` wraps an `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html`. This represents a UI window displayed on the screen for accessibility purposes, including interactive windows like dialogs or popup windows. It is important to note that a UiWindow instance caches a snapshot of a window state. If the underlying window closes or changes and it becomes stale, `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow` will automatically check and refresh its state internally before executing any methods.

Requires API level 24 or higher for multi-window mode.

## Summary

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object.html object)` |
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObject2` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#findObject(androidx.test.uiautomator.BySelector)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/BySelector selector)` Searches all elements in the window root and returns the first one to match the ` selector`, or `null` if no matching objects are found in this window. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/test/uiautomator/UiObject2>` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#findObjects(androidx.test.uiautomator.BySelector)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/BySelector selector)` Searches all elements under in the window root and returns those that match the ` selector`. |
| `int` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#getDisplayId()()` Gets the ID of the display containing this window. |
| `int` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#getId()()` Returns the ID of this window. |
| `int` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#getLayer()()` Returns the layer (Z-order) of the window. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#getPackageName()()` Returns the name of the package that this window belongs to. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/test/uiautomator/UiObject2` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#getRootObject()()` Gets the root node in the window as a `https://developer.android.com/reference/androidx/test/uiautomator/UiObject2`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#getTitle()()` Returns the title of the window as a String. |
| `int` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#getType()()` Returns the type of the window (e.g., `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#TYPE_APPLICATION`). |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#getVisibleBounds()()` Returns this window's visible bounds clipped to the size of the display. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#hasObject(androidx.test.uiautomator.BySelector)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/BySelector selector)` Returns `true` if there is an element in the window which matches the `selector`. |
| `int` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#hashCode()()` |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#isActive()()` Returns if this window is active (the one the user is currently interacting with). |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#isFocused()()` Returns if this window has input focus. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiWindow#isInPictureInPictureMode()()` Returns if the window is in picture-in-picture mode. |
| `@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/UiWindow#toString()()` |

## Public methods

### equals

```
public boolean equals(Object object)
```

### findObject

```
public UiObject2 findObject(@NonNull BySelector selector)
```

Searches all elements in the window root and returns the first one to match the `
selector`, or `null` if no matching objects are found in this window.

### findObjects

```
public @NonNull List<UiObject2> findObjects(@NonNull BySelector selector)
```

Searches all elements under in the window root and returns those that match the `
selector`.

### getDisplayId

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

```
public int getDisplayId()
```

Gets the ID of the display containing this window.

| Returns |
|---|---|
| `int` | The current display ID, or `https://developer.android.com/reference/android/view/Display.html#DEFAULT_DISPLAY` if the API level is \<30. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#getDisplayId()` |   |

### getId

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

```
public int getId()
```

Returns the ID of this window.

### getLayer

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

```
public int getLayer()
```

Returns the layer (Z-order) of the window. Higher layers are drawn on top of lower layers.

| Returns |
|---|---|
| `int` | The layer rank. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#getLayer()` |   |

### getPackageName

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

```
public @Nullable String getPackageName()
```

Returns the name of the package that this window belongs to.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | The name of the package, or `null` if the root object is not available. |

### getRootObject

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

```
public @Nullable UiObject2 getRootObject()
```

Gets the root node in the window as a `https://developer.android.com/reference/androidx/test/uiautomator/UiObject2`.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/test/uiautomator/UiObject2` | The root `https://developer.android.com/reference/androidx/test/uiautomator/UiObject2`, or `null` if the root node is not available or cannot be wrapped. The returned `https://developer.android.com/reference/androidx/test/uiautomator/UiObject2` should be recycled by the caller if it holds onto the reference. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#getRoot()` |   |

### getTitle

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

```
public @Nullable String getTitle()
```

Returns the title of the window as a String.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | The title as a String, or null if the window has no title, or if API level \<24. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#getTitle()` |   |

### getType

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

```
public int getType()
```

Returns the type of the window (e.g., `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#TYPE_APPLICATION`).

| Returns |
|---|---|
| `int` | The type. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#getType()` |   |

### getVisibleBounds

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

```
public @NonNull Rect getVisibleBounds()
```

Returns this window's visible bounds clipped to the size of the display.

### hasObject

```
public boolean hasObject(@NonNull BySelector selector)
```

Returns `true` if there is an element in the window which matches the `selector`.

### hashCode

```
public int hashCode()
```

### isActive

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

```
public boolean isActive()
```

Returns if this window is active (the one the user is currently interacting with).

| Returns |
|---|---|
| `boolean` | `true` if the window is active. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#isActive()` |   |

### isFocused

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

```
public boolean isFocused()
```

Returns if this window has input focus.

| Returns |
|---|---|
| `boolean` | `true` if this window has input focus. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#isFocused()` |   |

### isInPictureInPictureMode

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

```
public boolean isInPictureInPictureMode()
```

Returns if the window is in picture-in-picture mode.

| Returns |
|---|---|
| `boolean` | `true` if the window is in picture-in-picture mode, `false` otherwise or if API level is \<26. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html#isInPictureInPictureMode()` |   |

### toString

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