# UiDevice

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

*** ** * ** ***


```
class UiDevice : Searchable
```

<br />

*** ** * ** ***

UiDevice provides access to state information about the device. You can also use this class to simulate user actions on the device, such as pressing the d-pad or pressing the Home and Menu buttons.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#clearLastTraversedText()()` Clears the text from the last UI traversal event. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#click(int,int)(x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, y: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Perform a click at arbitrary coordinates on the default display specified by the user. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#drag(int,int,int,int,int)(startX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, startY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, endX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, endY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, steps: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Performs a swipe from one coordinate to another coordinate on the default display. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#dumpWindowHierarchy(java.io.File)(dest: https://developer.android.com/reference/java/io/File.html)` Dumps every window's layout hierarchy to a `https://developer.android.com/reference/java/io/File.html` in XML format. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[dumpWindowHierarchy](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#dumpWindowHierarchy(java.lang.String))(fileName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` **This function is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#dumpWindowHierarchy(java.io.File)` or `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#dumpWindowHierarchy(java.io.OutputStream)` instead. <br /> |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#dumpWindowHierarchy(java.io.OutputStream)(out: https://developer.android.com/reference/java/io/OutputStream.html)` Dumps every window's layout hierarchy to an `https://developer.android.com/reference/java/io/OutputStream.html` in XML format. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/Discouraged(message = "Can be useful for simple commands, but lacks support for proper error" + " handling, input data, or complex commands (quotes, pipes) that can be obtained " + "from UiAutomation#executeShellCommandRwe or similar utilities.") https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#executeShellCommand(java.lang.String)(cmd: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Executes a shell command using shell user identity, and return the standard output in string. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2!` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#findObject(androidx.test.uiautomator.BySelector)(selector: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/BySelector)` Returns the first object to match the `selector` criteria, or null if no matching objects are found. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#findObject(androidx.test.uiautomator.UiSelector)(selector: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector)` Returns a UiObject which represents a view that matches the specified selector criteria. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2!>` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#findObjects(androidx.test.uiautomator.BySelector)(selector: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/BySelector)` Returns all objects that match the `selector` criteria. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWindow?` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#findWindow(androidx.test.uiautomator.ByWindowSelector)(selector: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector)` Returns the first top-level window that matches the `selector` criteria, or null if no matching windows are found. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWindow!>` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#findWindows(androidx.test.uiautomator.ByWindowSelector)(selector: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector)` Returns all windows that match the `selector` criteria. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#freezeRotation()()` Freezes the default display rotation at its current state. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 30) https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#freezeRotation(int)(displayId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Freezes the rotation of the display with `displayId` at its current state. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `[getCurrentActivityName](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getCurrentActivityName())()` **This function is deprecated.** The results returned should be considered unreliable <br /> |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getCurrentPackageName()()` Retrieves the name of the last package to report accessibility events. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getDisplayHeight()()` Gets the height of the default display, in pixels. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getDisplayHeight(int)(displayId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Gets the height of the display with `displayId`, in pixels. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getDisplayRotation()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getDisplayRotation(int)(displayId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` |
| `https://developer.android.com/reference/android/graphics/Point.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getDisplaySizeDp()()` Returns the default display size in dp (device-independent pixel). |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getDisplayWidth()()` Gets the width of the default display, in pixels. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getDisplayWidth(int)(displayId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Gets the width of the display with `displayId`, in pixels. |
| `java-static https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice` | `[getInstance](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getInstance())()` **This function is deprecated.** Should use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getInstance(android.app.Instrumentation)` instead. <br /> |
| `java-static https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getInstance(android.app.Instrumentation)(instrumentation: https://developer.android.com/reference/android/app/Instrumentation.html)` Retrieves a singleton instance of UiDevice. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getLastTraversedText()()` Retrieves the text from the last UI traversal event received. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getLauncherPackageName()()` Retrieves the default launcher package name. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getProductName()()` Retrieves the product name of the device. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html!>` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getWindowRoots()()` Returns a list containing the root `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html`s for each active window. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#hasAnyWatcherTriggered()()` Checks if any registered `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher` have triggered. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#hasObject(androidx.test.uiautomator.BySelector)(selector: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/BySelector)` Returns whether there is a match for the given `selector` criteria. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#hasWatcherTriggered(java.lang.String)(watcherName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)` Checks if a specific registered `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher` has triggered. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#hasWindow(androidx.test.uiautomator.ByWindowSelector)(selector: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ByWindowSelector)` Returns whether there is a window match for the given `selector` criteria. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#isNaturalOrientation()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#isScreenOn()()` Checks the power manager if the default display is ON. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#openNotification()()` Opens the notification shade. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#openQuickSettings()()` Opens the Quick Settings shade. |
| `U!` | `<U> https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#performActionAndWait(java.lang.Runnable,androidx.test.uiautomator.EventCondition<U>,long)( action: https://developer.android.com/reference/java/lang/Runnable.html, condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/EventCondition<U!>, timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html )` Performs the provided `action` and waits for the `condition` to be met. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressBack()()` Simulates a short press on the BACK button. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressDPadCenter()()` Simulates a short press on the CENTER button. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressDPadDown()()` Simulates a short press on the DOWN button. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressDPadLeft()()` Simulates a short press on the LEFT button. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressDPadRight()()` Simulates a short press on the RIGHT button. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressDPadUp()()` Simulates a short press on the UP button. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressDelete()()` Simulates a short press on the DELETE key. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressEnter()()` Simulates a short press on the ENTER key. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressHome()()` Simulates a short press on the HOME button. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressKeyCode(int)(keyCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Simulates a short press using a key code. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressKeyCode(int,int)(keyCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, metaState: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Simulates a short press using a key code. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressKeyCodes(int[])(keyCodes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>)` Presses one or more keys. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressKeyCodes(int[],int)(keyCodes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>, metaState: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Presses one or more keys. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressMenu()()` Simulates a short press on the MENU button. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressRecentApps()()` Simulates a short press on the Recent Apps button. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#pressSearch()()` Simulates a short press on the SEARCH button. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#registerWatcher(java.lang.String,androidx.test.uiautomator.UiWatcher)(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, watcher: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher?)` Registers a `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher` to run automatically when the testing framework is unable to find a match using a `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#removeWatcher(java.lang.String)(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)` Removes a previously registered `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#resetWatcherTriggers()()` Resets a `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher` that has been triggered. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#runWatchers()()` This method forces all registered watchers to run. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[setCompressedLayoutHeirarchy](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setCompressedLayoutHeirarchy(boolean))(compressed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` **This function is deprecated.** Typo in function name, should use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setCompressedLayoutHierarchy(boolean)` instead. <br /> |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setCompressedLayoutHierarchy(boolean)(compressed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Enables or disables layout hierarchy compression. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationLandscape()()` Orients the default display to its landscape orientation (width \>= height) and freezes rotation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 30) https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationLandscape(int)(displayId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Orients the display with `displayId` to its landscape orientation (width \>= height) and freezes rotation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationLeft()()` Orients the default display to the left and freezes rotation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 30) https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationLeft(int)(displayId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Orients the display with `displayId` to the left and freezes rotation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationNatural()()` Orients the default display to its natural orientation and freezes rotation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 30) https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationNatural(int)(displayId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Orients the display with `displayId` to its natural orientation and freezes rotation . |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationPortrait()()` Orients the default display to its portrait orientation (height \>= width) and freezes rotation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 30) https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationPortrait(int)(displayId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Orients the display with `displayId` to its portrait orientation (height \>= width) and freezes rotation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationRight()()` Orients the default display to the right and freezes rotation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 30) https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationRight(int)(displayId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Orients the display with `displayId` to the right and freezes rotation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#sleep()()` This method simply presses the power button if the default display is ON, else it does nothing if the default display is already OFF. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#swipe(android.graphics.Point[],int)(segments: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/android/graphics/Point.html!>, segmentSteps: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Performs a swipe between points in the Point array on the default display. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#swipe(int,int,int,int,int)(startX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, startY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, endX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, endY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, steps: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Performs a swipe from one coordinate to another on the default display using the number of steps to determine smoothness and speed. |
| `https://developer.android.com/reference/android/graphics/Bitmap.html?` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#takeScreenshot()()` Take a screenshot of the default display. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#takeScreenshot(java.io.File)(storePath: https://developer.android.com/reference/java/io/File.html)` Take a screenshot of the default display and store it as PNG Default scale of 1.0f (original size) and 90% quality is used The screenshot is adjusted per screen rotation |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#takeScreenshot(java.io.File,float,int)(storePath: https://developer.android.com/reference/java/io/File.html, scale: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, quality: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Take a screenshot of the default display and store it as PNG The screenshot is adjusted per screen rotation |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#unfreezeRotation()()` Un-freezes the default display rotation allowing its contents to rotate with its physical rotation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 30) https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#unfreezeRotation(int)(displayId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Un-freezes the rotation of the display with `displayId` allowing its contents to rotate with its physical rotation. |
| `U!` | `<U> https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#wait(androidx.test.uiautomator.Condition<? super androidx.test.uiautomator.UiDevice,U>,long)(condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Condition<https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice!, U!>, timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Waits for given the `condition` to be met. |
| `U!` | `<U> https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#wait(androidx.test.uiautomator.SearchCondition<U>,long)(condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/SearchCondition<U!>, timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Waits for given the `condition` to be met. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#waitForIdle()()` Waits for the current application to idle. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#waitForIdle(long)(timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Waits for the current application to idle. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#waitForWindowUpdate(java.lang.String,long)(packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Waits for a window content update event to occur. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#wakeUp()()` This method simulates pressing the power button if the default display is OFF, else it does nothing if the default display is already ON. |

| ### Extension functions |
|---|---|
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#(androidx.test.uiautomator.UiDevice).activeWindow()()` Returns the active window. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#(androidx.test.uiautomator.UiDevice).onElement(kotlin.Long,kotlin.Long,kotlin.Function1)( timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, pollIntervalMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, block: https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Performs a DFS on the accessibility tree starting from the root node in the active window and returns the first node matching the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).onElement(kotlin.Long,kotlin.Long,kotlin.Function1)`. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2?` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#(androidx.test.uiautomator.UiDevice).onElementOrNull(kotlin.Long,kotlin.Long,kotlin.Function1)( timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, pollIntervalMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, block: https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Performs a DFS on the accessibility tree starting from the root node in the active window and returns the first node matching the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).onElementOrNull(kotlin.Long,kotlin.Long,kotlin.Function1)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2>` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#(androidx.test.uiautomator.UiDevice).onElements(kotlin.Long,kotlin.Long,kotlin.Function1)( timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, pollIntervalMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, block: https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Performs a DFS on the accessibility tree starting from this node and returns all the nodes matching the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).onElements(kotlin.Long,kotlin.Long,kotlin.Function1)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#(androidx.test.uiautomator.UiDevice).pressDelete(kotlin.Int)(count: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Similar to `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).type(kotlin.String)` but presses the delete key for the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).pressDelete(kotlin.Int)` times. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#(androidx.test.uiautomator.UiDevice).type(kotlin.String)(text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Types the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).type(kotlin.String)` string simulating key press through `https://developer.android.com/reference/android/app/Instrumentation.html#sendKeySync(android.view.KeyEvent)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#(androidx.test.uiautomator.UiDevice).waitForAppToBeVisible(kotlin.String,kotlin.Long)(appPackageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Waits for an application to become visible. |
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#(androidx.test.uiautomator.UiDevice).waitForRootInActiveWindow(kotlin.Long,kotlin.Long,kotlin.Boolean)( timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, sleepIntervalMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, clearCache: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Waits for the root node to become available in this window. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/StableResult` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#(androidx.test.uiautomator.UiDevice).waitForStableInActiveWindow(kotlin.Long,kotlin.Long,kotlin.Long,kotlin.Boolean)( stableTimeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, stableIntervalMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, stablePollIntervalMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, requireStableScreenshot: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Waits for the root node of the active window to become stable. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/view/accessibility/AccessibilityWindowInfo.html>` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#(androidx.test.uiautomator.UiDevice).windows()()` Returns all the windows on all the displays. |

## Public functions

### clearLastTraversedText

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

```
fun clearLastTraversedText(): Unit
```

Clears the text from the last UI traversal event. See `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getLastTraversedText()`.

### click

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

```
fun click(x: Int, y: Int): Boolean
```

Perform a click at arbitrary coordinates on the default display specified by the user.

| Parameters |
|---|---|
| `x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | coordinate |
| `y: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | coordinate |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the click succeeded else false |

### drag

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

```
fun drag(startX: Int, startY: Int, endX: Int, endY: Int, steps: Int): Boolean
```

Performs a swipe from one coordinate to another coordinate on the default display. You can control the smoothness and speed of the swipe by specifying the number of steps. Each step execution is throttled to the length of a frame per step (throttled by VSync).

| Parameters |
|---|---|
| `startX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | X-axis value for the starting coordinate |
| `startY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Y-axis value for the starting coordinate |
| `endX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | X-axis value for the ending coordinate |
| `endY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Y-axis value for the ending coordinate |
| `steps: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | is the number of steps for the swipe action |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if swipe is performed, false if the operation fails or the coordinates are invalid |

### dumpWindowHierarchy

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

```
fun dumpWindowHierarchy(dest: File): Unit
```

Dumps every window's layout hierarchy to a `https://developer.android.com/reference/java/io/File.html` in XML format.

| Parameters |
|---|---|
| `dest: https://developer.android.com/reference/java/io/File.html` | The file in which to store the window hierarchy information. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | if an I/O error occurs |

### dumpWindowHierarchy

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

```
fun [dumpWindowHierarchy](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#dumpWindowHierarchy(java.lang.String))(fileName: String): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#dumpWindowHierarchy(java.io.File)` or `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#dumpWindowHierarchy(java.io.OutputStream)` instead.

Dumps every window's layout hierarchy to a file in XML format.

| Parameters |
|---|---|
| `fileName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The file path in which to store the window hierarchy information. Relative file paths are stored the application's internal private storage location. |

### dumpWindowHierarchy

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

```
fun dumpWindowHierarchy(out: OutputStream): Unit
```

Dumps every window's layout hierarchy to an `https://developer.android.com/reference/java/io/OutputStream.html` in XML format.

| Parameters |
|---|---|
| `out: https://developer.android.com/reference/java/io/OutputStream.html` | The output stream that the window hierarchy information is written to. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | if an I/O error occurs |

### executeShellCommand

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

```
@Discouraged(message = "Can be useful for simple commands, but lacks support for proper error"
            + " handling, input data, or complex commands (quotes, pipes) that can be obtained "
            + "from UiAutomation#executeShellCommandRwe or similar utilities.")
fun executeShellCommand(cmd: String): String
```

Executes a shell command using shell user identity, and return the standard output in string.

Calling function with large amount of output will have memory impacts, and the function call will block if the command executed is blocking.

| Parameters |
|---|---|
| `cmd: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | the command to run |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | the standard output of the command |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | if an I/O error occurs while reading output |

### findObject

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

```
fun findObject(selector: BySelector): UiObject2!
```

Returns the first object to match the `selector` criteria, or null if no matching objects are found.

### findObject

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

```
fun findObject(selector: UiSelector): UiObject
```

Returns a UiObject which represents a view that matches the specified selector criteria.

| Parameters |
|---|---|
| `selector: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector` |   |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject` | UiObject object |

### findObjects

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

```
fun findObjects(selector: BySelector): (Mutable)List<UiObject2!>
```

Returns all objects that match the `selector` criteria.

### findWindow

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

```
fun findWindow(selector: ByWindowSelector): UiWindow?
```

Returns the first top-level window that matches the `selector` criteria, or null if no matching windows are found.

### findWindows

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

```
fun findWindows(selector: ByWindowSelector): (Mutable)List<UiWindow!>
```

Returns all windows that match the `selector` criteria. For convenience the returned list is sorted in descending layer Z-order, ensuring the root of the topmost interactable window is reported first.

### freezeRotation

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

```
fun freezeRotation(): Unit
```

Freezes the default display rotation at its current state.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | never |

### freezeRotation

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

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

Freezes the rotation of the display with `displayId` at its current state.

Note: Only works on Android API level 30 (R) or above, where multi-display is officially supported.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | when the display with `displayId` is not accessible. |

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

### getCurrentActivityName

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

```
fun [getCurrentActivityName](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getCurrentActivityName())(): String!
```

> [!CAUTION]
> **This function is deprecated.**   
>
> The results returned should be considered unreliable

Retrieves the last activity to report accessibility events.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | String name of activity |

### getCurrentPackageName

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

```
fun getCurrentPackageName(): String!
```

Retrieves the name of the last package to report accessibility events.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | String name of package |

### getDisplayHeight

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

```
fun getDisplayHeight(): @Px Int
```

Gets the height of the default display, in pixels. The size is adjusted based on the current orientation of the display.

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | height in pixels |

### getDisplayHeight

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

```
fun getDisplayHeight(displayId: Int): @Px Int
```

Gets the height of the display with `displayId`, in pixels. The size is adjusted based on the current orientation of the display.

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | height in pixels |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | when the display with `displayId` is not accessible. |

### getDisplayRotation

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

```
fun getDisplayRotation(): Int
```

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the current rotation of the default display |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/Display.html#getRotation()` |   |

### getDisplayRotation

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

```
fun getDisplayRotation(displayId: Int): Int
```

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the current rotation of the display with `displayId` |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | when the display with `displayId` is not accessible. |

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

### getDisplaySizeDp

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

```
fun getDisplaySizeDp(): Point
```

Returns the default display size in dp (device-independent pixel).

The returned display size is adjusted per screen rotation. Also this will return the actual size of the screen, rather than adjusted per system decorations (like status bar).

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/Point.html` | a Point containing the display size in dp |

| See also |
|---|---|
| `https://developer.android.com/reference/android/util/DisplayMetrics.html#density` |   |

### getDisplayWidth

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

```
fun getDisplayWidth(): @Px Int
```

Gets the width of the default display, in pixels. The size is adjusted based on the current orientation of the display.

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | width in pixels |

### getDisplayWidth

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

```
fun getDisplayWidth(displayId: Int): @Px Int
```

Gets the width of the display with `displayId`, in pixels. The size is adjusted based on the current orientation of the display.

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | width in pixels |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | when the display with `displayId` is not accessible. |

### getInstance

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

```
java-static fun [getInstance](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getInstance())(): UiDevice
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Should use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#getInstance(android.app.Instrumentation)` instead. This version hides UiDevice's dependency on having an Instrumentation reference and is prone to misuse.

Retrieves a singleton instance of UiDevice

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice` | UiDevice instance |

### getInstance

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

```
java-static fun getInstance(instrumentation: Instrumentation): UiDevice
```

Retrieves a singleton instance of UiDevice. A new instance will be created if instrumentation is also new.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice` | UiDevice instance |

### getLastTraversedText

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

```
fun getLastTraversedText(): String!
```

Retrieves the text from the last UI traversal event received. You can use this method to read the contents in a WebView container because the accessibility framework fires events as each text is highlighted. You can write a test to perform directional arrow presses to focus on different elements inside a WebView, and call this method to get the text from each traversed element. If you are testing a view container that can return a reference to a Document Object Model (DOM) object, your test should use the view's DOM instead.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | text of the last traversal event, else return an empty string |

### getLauncherPackageName

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

```
fun getLauncherPackageName(): String!
```

Retrieves the default launcher package name.

As of Android 11 (API level 30), apps must declare the packages and intents they intend to query. To use this method, an app will need to include the following in its manifest:

```kotlin
<queries>
  <intent>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.HOME"/>
  </intent>
</queries>
```

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | package name of the default launcher |

### getProductName

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

```
fun getProductName(): String
```

Retrieves the product name of the device. This method provides information on what type of device the test is running on. This value is the same as returned by invoking #adb shell getprop ro.product.name.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | product name of the device |

### getWindowRoots

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

```
fun getWindowRoots(): (Mutable)List<AccessibilityNodeInfo!>
```

Returns a list containing the root `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html`s for each active window. For convenience the returned list is sorted in descending window order, ensuring the root of the topmost visible window is reported first.

### hasAnyWatcherTriggered

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

```
fun hasAnyWatcherTriggered(): Boolean
```

Checks if any registered `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher` have triggered. See `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#registerWatcher(java.lang.String,androidx.test.uiautomator.UiWatcher)` See `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#hasWatcherTriggered(java.lang.String)`

### hasObject

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

```
fun hasObject(selector: BySelector): Boolean
```

Returns whether there is a match for the given `selector` criteria.

### hasWatcherTriggered

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

```
fun hasWatcherTriggered(watcherName: String?): Boolean
```

Checks if a specific registered `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher` has triggered. See `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#registerWatcher(java.lang.String,androidx.test.uiautomator.UiWatcher)`. If a UiWatcher runs and its `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher#checkForCondition()` call returned `true`, then the UiWatcher is considered triggered. This is helpful if a watcher is detecting errors from ANR or crash dialogs and the test needs to know if a UiWatcher has been triggered.

| Parameters |
|---|---|
| `watcherName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` |   |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if triggered else false |

### hasWindow

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

```
fun hasWindow(selector: ByWindowSelector): Boolean
```

Returns whether there is a window match for the given `selector` criteria.

### isNaturalOrientation

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

```
fun isNaturalOrientation(): Boolean
```

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if default display is in its natural or flipped (180 degrees) orientation |

### isScreenOn

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

```
fun isScreenOn(): Boolean
```

Checks the power manager if the default display is ON.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the screen is ON else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` |   |

### openNotification

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

```
fun openNotification(): Boolean
```

Opens the notification shade.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### openQuickSettings

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

```
fun openQuickSettings(): Boolean
```

Opens the Quick Settings shade.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### performActionAndWait

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

```
fun <U> performActionAndWait(
    action: Runnable,
    condition: EventCondition<U!>,
    timeout: Long
): U!
```

Performs the provided `action` and waits for the `condition` to be met.

| Parameters |
|---|---|
| `action: https://developer.android.com/reference/java/lang/Runnable.html` | The `https://developer.android.com/reference/java/lang/Runnable.html` action to perform. |
| `condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/EventCondition<U!>` | The `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/EventCondition` to evaluate. |
| `timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | Maximum amount of time to wait in milliseconds. |

| Returns |
|---|---|
| `U!` | The final result returned by the condition. |

### pressBack

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

```
fun pressBack(): Boolean
```

Simulates a short press on the BACK button.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### pressDPadCenter

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

```
fun pressDPadCenter(): Boolean
```

Simulates a short press on the CENTER button.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### pressDPadDown

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

```
fun pressDPadDown(): Boolean
```

Simulates a short press on the DOWN button.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### pressDPadLeft

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

```
fun pressDPadLeft(): Boolean
```

Simulates a short press on the LEFT button.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### pressDPadRight

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

```
fun pressDPadRight(): Boolean
```

Simulates a short press on the RIGHT button.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### pressDPadUp

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

```
fun pressDPadUp(): Boolean
```

Simulates a short press on the UP button.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### pressDelete

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

```
fun pressDelete(): Boolean
```

Simulates a short press on the DELETE key.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### pressEnter

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

```
fun pressEnter(): Boolean
```

Simulates a short press on the ENTER key.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### pressHome

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

```
fun pressHome(): Boolean
```

Simulates a short press on the HOME button.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### pressKeyCode

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

```
fun pressKeyCode(keyCode: Int): Boolean
```

Simulates a short press using a key code. See `https://developer.android.com/reference/android/view/KeyEvent.html`

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### pressKeyCode

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

```
fun pressKeyCode(keyCode: Int, metaState: Int): Boolean
```

Simulates a short press using a key code. See `https://developer.android.com/reference/android/view/KeyEvent.html`.

| Parameters |
|---|---|
| `keyCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the key code of the event. |
| `metaState: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | an integer in which each bit set to 1 represents a pressed meta key |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### pressKeyCodes

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

```
fun pressKeyCodes(keyCodes: IntArray<Int>): Boolean
```

Presses one or more keys. Keys that change meta state are supported, and will apply their meta state to following keys. For example, you can simulate taking a screenshot on the device by pressing both the power and volume down keys.

```kotlin
pressKeyCodes(new int[]{KeyEvent.KEYCODE_POWER, KeyEvent.KEYCODE_VOLUME_DOWN})
```

| Parameters |
|---|---|
| `keyCodes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>` | array of key codes. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/KeyEvent.html` |   |

### pressKeyCodes

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

```
fun pressKeyCodes(keyCodes: IntArray<Int>, metaState: Int): Boolean
```

Presses one or more keys. Keys that change meta state are supported, and will apply their meta state to following keys. For example, you can simulate taking a screenshot on the device by pressing both the power and volume down keys.

```kotlin
pressKeyCodes(new int[]{KeyEvent.KEYCODE_POWER, KeyEvent.KEYCODE_VOLUME_DOWN})
```

| Parameters |
|---|---|
| `keyCodes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>` | array of key codes. |
| `metaState: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | an integer in which each bit set to 1 represents a pressed meta key |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/KeyEvent.html` |   |

### pressMenu

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

```
fun pressMenu(): Boolean
```

Simulates a short press on the MENU button.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### pressRecentApps

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

```
fun pressRecentApps(): Boolean
```

Simulates a short press on the Recent Apps button.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | never |

### pressSearch

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

```
fun pressSearch(): Boolean
```

Simulates a short press on the SEARCH button.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if successful, else return false |

### registerWatcher

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

```
fun registerWatcher(name: String?, watcher: UiWatcher?): Unit
```

Registers a `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher` to run automatically when the testing framework is unable to find a match using a `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiSelector`. See `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#runWatchers()`

| Parameters |
|---|---|
| `name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | to register the UiWatcher |
| `watcher: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher?` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher` |

### removeWatcher

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

```
fun removeWatcher(name: String?): Unit
```

Removes a previously registered `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher`. See `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#registerWatcher(java.lang.String,androidx.test.uiautomator.UiWatcher)`

| Parameters |
|---|---|
| `name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | used to register the UiWatcher |

### resetWatcherTriggers

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

```
fun resetWatcherTriggers(): Unit
```

Resets a `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher` that has been triggered. If a UiWatcher runs and its `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiWatcher#checkForCondition()` call returned `true`, then the UiWatcher is considered triggered. See `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#registerWatcher(java.lang.String,androidx.test.uiautomator.UiWatcher)`

### runWatchers

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

```
fun runWatchers(): Unit
```

This method forces all registered watchers to run. See `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#registerWatcher(java.lang.String,androidx.test.uiautomator.UiWatcher)`

### setCompressedLayoutHeirarchy

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

```
fun [setCompressedLayoutHeirarchy](https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setCompressedLayoutHeirarchy(boolean))(compressed: Boolean): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Typo in function name, should use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setCompressedLayoutHierarchy(boolean)` instead.

Enables or disables layout hierarchy compression. If compression is enabled, the layout hierarchy derived from the Acessibility framework will only contain nodes that are important for uiautomator testing. Any unnecessary surrounding layout nodes that make viewing and searching the hierarchy inefficient are removed.

| Parameters |
|---|---|
| `compressed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true to enable compression; else, false to disable |

### setCompressedLayoutHierarchy

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

```
fun setCompressedLayoutHierarchy(compressed: Boolean): Unit
```

Enables or disables layout hierarchy compression. If compression is enabled, the layout hierarchy derived from the Accessibility framework will only contain nodes that are important for uiautomator testing. Any unnecessary surrounding layout nodes that make viewing and searching the hierarchy inefficient are removed.

| Parameters |
|---|---|
| `compressed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true to enable compression; else, false to disable |

### setOrientationLandscape

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

```
fun setOrientationLandscape(): Unit
```

Orients the default display to its landscape orientation (width \>= height) and freezes rotation. Use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#unfreezeRotation()` to un-freeze the rotation.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | never |

### setOrientationLandscape

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

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

Orients the display with `displayId` to its landscape orientation (width \>= height) and freezes rotation. Use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#unfreezeRotation()` to un-freeze the rotation.

Note: Only works on Android API level 30 (R) or above, where multi-display is officially supported.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | when the display with `displayId` is not accessible. |

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

### setOrientationLeft

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

```
fun setOrientationLeft(): Unit
```

Orients the default display to the left and freezes rotation. Use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#unfreezeRotation()` to un-freeze the rotation.

Note: This rotation is relative to the natural orientation which depends on the device type (e.g. phone vs. tablet). Consider using `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationPortrait()` and `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationLandscape()`.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | never |

### setOrientationLeft

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

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

Orients the display with `displayId` to the left and freezes rotation. Use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#unfreezeRotation()` to un-freeze the rotation.

Note: This rotation is relative to the natural orientation which depends on the device type (e.g. phone vs. tablet). Consider using `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationPortrait()` and `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationLandscape()`.

Note: Only works on Android API level 30 (R) or above, where multi-display is officially supported.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | when the display with `displayId` is not accessible. |

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

### setOrientationNatural

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

```
fun setOrientationNatural(): Unit
```

Orients the default display to its natural orientation and freezes rotation. Use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#unfreezeRotation()` to un-freeze the rotation.

Note: The natural orientation depends on the device type (e.g. phone vs. tablet). Consider using `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationPortrait()` and `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationLandscape()`.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | never |

### setOrientationNatural

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

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

Orients the display with `displayId` to its natural orientation and freezes rotation . Use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#unfreezeRotation()` to un-freeze the rotation.

Note: The natural orientation depends on the device type (e.g. phone vs. tablet). Consider using `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationPortrait()` and `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationLandscape()`.

Note: Only works on Android API level 30 (R) or above, where multi-display is officially supported.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | when the display with `displayId` is not accessible. |

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

### setOrientationPortrait

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

```
fun setOrientationPortrait(): Unit
```

Orients the default display to its portrait orientation (height \>= width) and freezes rotation. Use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#unfreezeRotation()` to un-freeze the rotation.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | never |

### setOrientationPortrait

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

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

Orients the display with `displayId` to its portrait orientation (height \>= width) and freezes rotation. Use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#unfreezeRotation()` to un-freeze the rotation.

Note: Only works on Android API level 30 (R) or above, where multi-display is officially supported.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | when the display with `displayId` is not accessible. |

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

### setOrientationRight

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

```
fun setOrientationRight(): Unit
```

Orients the default display to the right and freezes rotation. Use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#unfreezeRotation()` to un-freeze the rotation.

Note: This rotation is relative to the natural orientation which depends on the device type (e.g. phone vs. tablet). Consider using `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationPortrait()` and `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationLandscape()`.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | never |

### setOrientationRight

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

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

Orients the display with `displayId` to the right and freezes rotation. Use `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#unfreezeRotation()` to un-freeze the rotation.

Note: This rotation is relative to the natural orientation which depends on the device type (e.g. phone vs. tablet). Consider using `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationPortrait()` and `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#setOrientationLandscape()`.

Note: Only works on Android API level 30 (R) or above, where multi-display is officially supported.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | when the display with `displayId` is not accessible. |

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

### sleep

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

```
fun sleep(): Unit
```

This method simply presses the power button if the default display is ON, else it does nothing if the default display is already OFF.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` |   |

### swipe

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

```
fun swipe(segments: Array<Point!>, segmentSteps: Int): Boolean
```

Performs a swipe between points in the Point array on the default display. Each step execution is throttled to the length of a frame per step (throttled by VSync).

| Parameters |
|---|---|
| `segments: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/android/graphics/Point.html!>` | is Point array containing at least one Point object |
| `segmentSteps: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | steps to inject between two Points |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true on success |

### swipe

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

```
fun swipe(startX: Int, startY: Int, endX: Int, endY: Int, steps: Int): Boolean
```

Performs a swipe from one coordinate to another on the default display using the number of steps to determine smoothness and speed. Each step execution is throttled to the length of a frame per step (throttled by VSync).

| Parameters |
|---|---|
| `startX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | X-axis value for the starting coordinate |
| `startY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Y-axis value for the starting coordinate |
| `endX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | X-axis value for the ending coordinate |
| `endY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Y-axis value for the ending coordinate |
| `steps: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | is the number of move steps sent to the system |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | false if the operation fails or the coordinates are invalid |

### takeScreenshot

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

```
fun takeScreenshot(): Bitmap?
```

Take a screenshot of the default display.

The screenshot is adjusted per screen rotation.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html?` | The screenshot bitmap on success, `null` otherwise |

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/UiAutomation.html#takeScreenshot()` |   |

### takeScreenshot

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

```
fun takeScreenshot(storePath: File): Boolean
```

Take a screenshot of the default display and store it as PNG Default scale of 1.0f (original size) and 90% quality is used The screenshot is adjusted per screen rotation

| Parameters |
|---|---|
| `storePath: https://developer.android.com/reference/java/io/File.html` | where the PNG should be written to |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if screen shot is created successfully, false otherwise |

### takeScreenshot

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

```
fun takeScreenshot(storePath: File, scale: Float, quality: Int): Boolean
```

Take a screenshot of the default display and store it as PNG The screenshot is adjusted per screen rotation

| Parameters |
|---|---|
| `storePath: https://developer.android.com/reference/java/io/File.html` | where the PNG should be written to |
| `scale: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | scale the screenshot down if needed; 1.0f for original size |
| `quality: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | quality of the PNG compression; range: 0-100 |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if screen shot is created successfully, false otherwise |

### unfreezeRotation

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

```
fun unfreezeRotation(): Unit
```

Un-freezes the default display rotation allowing its contents to rotate with its physical rotation. During testing, it is best to keep the default display frozen in a specific orientation.

Note: Need to wait a short period for the rotation animation to complete before performing another operation.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | never |

### unfreezeRotation

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

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

Un-freezes the rotation of the display with `displayId` allowing its contents to rotate with its physical rotation. During testing, it is best to keep the display frozen in a specific orientation.

Note: Need to wait a short period for the rotation animation to complete before performing another operation.

Note: Some secondary displays don't have rotation sensors and therefore won't respond to this method.

Note: Only works on Android API level 30 (R) or above, where multi-display is officially supported.

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

### wait

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

```
fun <U> wait(condition: Condition<UiDevice!, U!>, timeout: Long): U!
```

Waits for given the `condition` to be met.

| Parameters |
|---|---|
| `condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Condition<https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice!, U!>` | The `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Condition` to evaluate. |
| `timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | Maximum amount of time to wait in milliseconds. |

| Returns |
|---|---|
| `U!` | The final result returned by the `condition`, or null if the `condition` was not met before the `timeout`. |

### wait

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

```
fun <U> wait(condition: SearchCondition<U!>, timeout: Long): U!
```

Waits for given the `condition` to be met.

| Parameters |
|---|---|
| `condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/SearchCondition<U!>` | The `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/SearchCondition` to evaluate. |
| `timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | Maximum amount of time to wait in milliseconds. |

| Returns |
|---|---|
| `U!` | The final result returned by the `condition`, or null if the `condition` was not met before the `timeout`. |

### waitForIdle

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

```
fun waitForIdle(): Unit
```

Waits for the current application to idle.

**Note:** Usage of this API in tests will result in non-deterministic tests. So this API should only be used as a last resort and **only** when there are no other alternatives available.

Default wait timeout is 10 seconds

### waitForIdle

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

```
fun waitForIdle(timeout: Long): Unit
```

Waits for the current application to idle.

**Note:** Usage of this API in tests will result in non-deterministic tests. So this API should only be used as a last resort and **only** when there are no other alternatives available.

| Parameters |
|---|---|
| `timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | in milliseconds |

### waitForWindowUpdate

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

```
fun waitForWindowUpdate(packageName: String?, timeout: Long): Boolean
```

Waits for a window content update event to occur. If a package name for the window is specified, but the current window does not have the same package name, the function returns immediately.

| Parameters |
|---|---|
| `packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | the specified window package name (can be `null`). If `null`, a window update from any front-end window will end the wait |
| `timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | the timeout for the wait |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if a window update occurred, false if timeout has elapsed or if the current window does not have the specified package name |

### wakeUp

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

```
fun wakeUp(): Unit
```

This method simulates pressing the power button if the default display is OFF, else it does nothing if the default display is already ON.

If the default display was OFF and it just got turned ON, this method will insert a 500ms delay for the device to wake up and accept input.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` |   |

## Extension functions

### UiDevice.activeWindow

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/UiDeviceExt.kt+function:activeWindow)

```
fun UiDevice.activeWindow(): AccessibilityWindowInfo
```

Returns the active window.

### UiDevice.onElement

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/UiDeviceExt.kt+function:onElement)

```
fun UiDevice.onElement(
    timeoutMs: Long = 10000,
    pollIntervalMs: Long = 100,
    block: AccessibilityNodeInfo.() -> Boolean
): UiObject2
```

Performs a DFS on the accessibility tree starting from the root node in the active window and returns the first node matching the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).onElement(kotlin.Long,kotlin.Long,kotlin.Function1)`. The node is returned as an `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` that allows interacting with it. If the requested node doesn't exist, a `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ElementNotFoundException` is thrown. Internally it works searching periodically every `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).onElement(kotlin.Long,kotlin.Long,kotlin.Function1)`.

Example:

```kotlin
uiDevice.onElement { textAsString == "Search" }.click()
```

| Parameters |
|---|---|
| `timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 10000` | a timeout to find the element that satisfies the given condition. |
| `pollIntervalMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 100` | an interval to wait before rechecking the accessibility tree for updates. |
| `block: https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | a block that specifies a condition on the node to find. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` | a `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` from a node that matches the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).onElement(kotlin.Long,kotlin.Long,kotlin.Function1)` condition. |

### UiDevice.onElementOrNull

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/UiDeviceExt.kt+function:onElementOrNull)

```
fun UiDevice.onElementOrNull(
    timeoutMs: Long = 10000,
    pollIntervalMs: Long = 100,
    block: AccessibilityNodeInfo.() -> Boolean
): UiObject2?
```

Performs a DFS on the accessibility tree starting from the root node in the active window and returns the first node matching the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).onElementOrNull(kotlin.Long,kotlin.Long,kotlin.Function1)`. The node is returned as an `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` that allows interacting with it. If the requested node doesn't exist, null is returned. Internally it works searching periodically every `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).onElementOrNull(kotlin.Long,kotlin.Long,kotlin.Function1)`.

Example:

```kotlin
uiDevice.onElement { textAsString == "Search" }.click()
```

| Parameters |
|---|---|
| `timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 10000` | a timeout to find the element that satisfies the given condition. |
| `pollIntervalMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 100` | an interval to wait before rechecking the accessibility tree for updates. |
| `block: https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | a block that specifies a condition on the node to find. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2?` | a `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` from a node that matches the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).onElementOrNull(kotlin.Long,kotlin.Long,kotlin.Function1)` condition or null. |

### UiDevice.onElements

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/UiDeviceExt.kt+function:onElements)

```
fun UiDevice.onElements(
    timeoutMs: Long = 10000,
    pollIntervalMs: Long = 100,
    block: AccessibilityNodeInfo.() -> Boolean
): List<UiObject2>
```

Performs a DFS on the accessibility tree starting from this node and returns all the nodes matching the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).onElements(kotlin.Long,kotlin.Long,kotlin.Function1)`. This method stops waiting as soon as a single node with the given condition is returned. The nodes returned are `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` that allow interacting with them. Internally it works searching periodically every `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).onElements(kotlin.Long,kotlin.Long,kotlin.Function1)`.

Example:

```kotlin
node.onElements { className == Button::class.java.name }
```

If multiple nodes are expected but they appear at different times, it's recommended to call `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(android.view.accessibility.AccessibilityNodeInfo).waitForStable(kotlin.Long,kotlin.Long,kotlin.Long,kotlin.Boolean)` before, to ensure any operation is complete.

| Parameters |
|---|---|
| `timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 10000` | a timeout to find the element that satisfies the given condition. |
| `pollIntervalMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 100` | an interval to wait before rechecking the accessibility tree for updates. |
| `block: https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | a block that specifies a condition on the node to find. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2>` | a list of `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` from nodes that matches the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).onElements(kotlin.Long,kotlin.Long,kotlin.Function1)` condition. |

### UiDevice.pressDelete

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/UiDeviceExt.kt+function:pressDelete)

```
fun UiDevice.pressDelete(count: Int): Unit
```

Similar to `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).type(kotlin.String)` but presses the delete key for the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).pressDelete(kotlin.Int)` times.

| Parameters |
|---|---|
| `count: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | how many times the press delete key should be pressed. |

### UiDevice.type

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/UiDeviceExt.kt+function:type)

```
fun UiDevice.type(text: String): Unit
```

Types the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).type(kotlin.String)` string simulating key press through `https://developer.android.com/reference/android/app/Instrumentation.html#sendKeySync(android.view.KeyEvent)`. This is similar to tapping the keys on a virtual keyboard and will trigger the same listeners in the target app, as opposed to `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html#setText(java.lang.CharSequence)` that programmatically sets the given text in the target node.

| Parameters |
|---|---|
| `text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | the text to type. |

### UiDevice.waitForAppToBeVisible

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/UiDeviceExt.kt+function:waitForAppToBeVisible)

```
fun UiDevice.waitForAppToBeVisible(
    appPackageName: String,
    timeoutMs: Long = 10000
): Boolean
```

Waits for an application to become visible. Note that internally it checks if an accessibility node with the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).waitForAppToBeVisible(kotlin.String,kotlin.Long)` exists in the accessibility tree.

| Parameters |
|---|---|
| `appPackageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | the package name of the app to wait for. By default is the target app package name. |
| `timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 10000` | a timeout for the app to become visible. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | whether the app became visible in the given timeout. |

### UiDevice.waitForRootInActiveWindow

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/UiDeviceExt.kt+function:waitForRootInActiveWindow)

```
fun UiDevice.waitForRootInActiveWindow(
    timeoutMs: Long = 10000,
    sleepIntervalMs: Long = 100,
    clearCache: Boolean = true
): AccessibilityNodeInfo
```

Waits for the root node to become available in this window.

| Parameters |
|---|---|
| `timeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 10000` | a timeout for the root node to become available. |
| `sleepIntervalMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 100` | a interval to wait before retrying checking if the node is available. |
| `clearCache: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = true` | whether the accessibility nodes cache should be cleared when checking. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html` | the root node for this window. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if the root node in the active window cannot be acquired before the give timeout `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).waitForRootInActiveWindow(kotlin.Long,kotlin.Long,kotlin.Boolean)`. |

### UiDevice.waitForStableInActiveWindow

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/UiDeviceExt.kt+function:waitForStableInActiveWindow)

```
fun UiDevice.waitForStableInActiveWindow(
    stableTimeoutMs: Long = 3000,
    stableIntervalMs: Long = 500,
    stablePollIntervalMs: Long = 50,
    requireStableScreenshot: Boolean = true
): StableResult
```

Waits for the root node of the active window to become stable.

A node is considered stable when it and its descendants have not changed over an interval of time. Optionally also the node image can be checked. Internally it works checking periodically that the internal properties of the node have not changed.

**Note** : Usage of this API in tests will result in non-deterministic tests. So, this API should only be used as a last resort and **only** when there are no other alternatives available.

| Parameters |
|---|---|
| `stableTimeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 3000` | a timeout for the wait operation, to ensure not waiting forever for stability. |
| `stableIntervalMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 500` | the interval during which the node should not be changing, in order to be considered stable. |
| `stablePollIntervalMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 50` | specifies how often the ui should be checked for changes. |
| `requireStableScreenshot: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = true` | specifies if also the bitmap of the node should not change over the specified `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiDevice).waitForStableInActiveWindow(kotlin.Long,kotlin.Long,kotlin.Long,kotlin.Boolean)`. Note that this won't work with elements that change constantly, like a video player. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/StableResult` | a `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/StableResult` containing the latest acquired element hierarchy and screenshot, and a flag indicating if the node was stable before timeout. The flag `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/StableResult#isTimeout()` is set to false if the node was stable before the timeout expired, true otherwise. |

### UiDevice.windows

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/UiDeviceExt.kt+function:windows)

```
fun UiDevice.windows(): List<AccessibilityWindowInfo>
```

Returns all the windows on all the displays.