# UiObject2

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

*** ** * ** ***


```
class UiObject2 : Searchable
```

<br />

*** ** * ** ***

Represents a UI element, and exposes methods for performing gestures (clicks, swipes) or searching through its children.

Unlike `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject`, `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` is bound to a particular view instance and can become stale if the underlying view object is destroyed. As a result, it may be necessary to call `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiDevice#findObject(androidx.test.uiautomator.BySelector)` to obtain a new `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` instance if the UI changes significantly.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#clear()()` Clears this object's text content if it is an editable field. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#click()()` Clicks on this object's center. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#click(long)(duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Clicks on this object's center for `duration` milliseconds. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#click(android.graphics.Point)(point: https://developer.android.com/reference/android/graphics/Point.html)` Clicks on a `point` within this object's visible bounds. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#click(android.graphics.Point,long)(point: https://developer.android.com/reference/android/graphics/Point.html, duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Clicks on a `point` within this object's visible bounds. |
| `U!` | `<U> https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#clickAndWait(androidx.test.uiautomator.EventCondition<U>,long)(condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/EventCondition<U!>, timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Clicks on this object's center, and waits for a `condition` to be met. |
| `U!` | `<U> https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#clickAndWait(android.graphics.Point,androidx.test.uiautomator.EventCondition<U>,long)(point: https://developer.android.com/reference/android/graphics/Point.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)` Clicks on a `point` within this object's visible bounds, and waits for a ` condition` to be met. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#drag(android.graphics.Point)(dest: https://developer.android.com/reference/android/graphics/Point.html)` Drags this object to the specified point. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#drag(android.graphics.Point,int)(dest: https://developer.android.com/reference/android/graphics/Point.html, speed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Drags this object to the specified point. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#equals(java.lang.Object)(object: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!)` |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2!` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#findObject(androidx.test.uiautomator.BySelector)(selector: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/BySelector)` Searches all elements under this object and returns the first one to match the ` selector`, or `null` if no matching objects 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/UiObject2!>` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#findObjects(androidx.test.uiautomator.BySelector)(selector: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/BySelector)` Searches all elements under this object and returns those that match the `selector`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#fling(androidx.test.uiautomator.Direction)(direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction)` Performs a fling gesture on this object. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#fling(androidx.test.uiautomator.Direction,int)(direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction, speed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Performs a fling gesture on this object. |
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getAccessibilityNodeInfo()()` Returns an up-to-date `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html` corresponding to this object's underlying `https://developer.android.com/reference/android/view/View.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getApplicationPackage()()` Returns the package name of the app that this object belongs to. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getChildCount()()` Returns the number of child elements directly under this object. |
| `(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/UiObject2#getChildren()()` Returns a collection of the child elements directly under this object. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getClassName()()` Returns the class name of this object's underlying `https://developer.android.com/reference/android/view/View.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getContentDescription()()` Returns this object's content description. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getDisplayId()()` Returns the ID of the display containing this object. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 24) https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getDrawingOrder()()` Returns the drawing order (z-index) of this object relative to its siblings. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getHint()()` Returns the hint text of this object, or null if hint text is not preset. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2!` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getParent()()` Returns this object's parent, or `null` if it has no parent. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getResourceName()()` Returns the fully qualified resource name for this object's ID. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getText()()` Returns this object's text content. |
| `https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getVisibleBounds()()` Returns this object's visible bounds. |
| `https://developer.android.com/reference/android/graphics/Point.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#getVisibleCenter()()` Returns a point in the center of this object's visible bounds. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#hasObject(androidx.test.uiautomator.BySelector)(selector: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/BySelector)` Returns `true` if there is a nested element which matches the `selector`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#hashCode()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#isCheckable()()` Returns `true` if this object is checkable. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#isChecked()()` Returns `true` if this object is checked. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#isClickable()()` Returns `true` if this object is clickable. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#isEnabled()()` Returns `true` if this object is enabled. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#isFocusable()()` Returns `true` if this object is focusable. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#isFocused()()` Returns `true` if this object is focused. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#isLongClickable()()` Returns `true` if this object is long clickable. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#isScrollable()()` Returns `true` if this object is scrollable. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#isSelected()()` Returns `true` if this object is selected. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#longClick()()` Performs a long click on this object's center. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#pinchClose(float)(percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Performs a pinch close gesture on this object. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#pinchClose(float,int)(percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, speed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Performs a pinch close gesture on this object. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#pinchOpen(float)(percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Performs a pinch open gesture on this object. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#pinchOpen(float,int)(percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, speed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Performs a pinch open gesture on this object. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#recycle()()` Recycle this object. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#scroll(androidx.test.uiautomator.Direction,float)(direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction, percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Performs a scroll gesture on this object. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#scroll(androidx.test.uiautomator.Direction,float,int)(direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction, percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, speed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Performs a scroll gesture on this object. |
| `U!` | `<U> https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#scrollUntil(androidx.test.uiautomator.Direction,androidx.test.uiautomator.Condition<? super androidx.test.uiautomator.UiObject2,U>)(direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction, condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Condition<https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2!, U!>)` Perform scroll actions in certain direction until a `condition` is satisfied or scroll has finished, e.g. to scroll until an object contain certain text is found: |
| `U!` | `<U> https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#scrollUntil(androidx.test.uiautomator.Direction,androidx.test.uiautomator.EventCondition<U>)(direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction, condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/EventCondition<U!>)` Perform scroll actions in certain direction until a `condition` is satisfied or scroll has finished, e.g. to scroll until a new window has appeared: |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#setGestureMargin(int)(margin: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the margins used for gestures in pixels. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#setGestureMarginPercentage(float)(percent: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Sets the percentage of gestures' margins to avoid touching too close to the edges, e.g. when scrolling up, phone open quick settings instead if gesture is close to the top. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#setGestureMargins(int,int,int,int)(left: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, top: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, right: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bottom: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the margins used for gestures in pixels. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#setGestureMarginsPercentage(float,float,float,float)( left: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, top: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, right: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, bottom: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Sets the percentage of gestures' margins to avoid touching too close to the edges, e.g. when scrolling up, phone open quick settings instead if gesture is close to the top. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#setText(java.lang.String)(text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)` Sets this object's text content if it is an editable field. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#swipe(androidx.test.uiautomator.Direction,float)(direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction, percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Performs a swipe gesture on this object. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#swipe(androidx.test.uiautomator.Direction,float,int)(direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction, percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, speed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Performs a swipe gesture on this object. |
| `U!` | `<U> https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#wait(androidx.test.uiautomator.Condition<? super androidx.test.uiautomator.UiObject2,U>,long)(condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Condition<https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2!, U!>, timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Waits for a `condition` to be met. |
| `U!` | `<U> https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#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 a `condition` to be met. |
| `U!` | `<U> https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#wait(androidx.test.uiautomator.UiObject2Condition<U>,long)(condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2Condition<U!>, timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Waits for a `condition` to be met. |

| ### Extension functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#(androidx.test.uiautomator.UiObject2).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 node associated to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` and returns the first node matching the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).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/UiObject2.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#(androidx.test.uiautomator.UiObject2).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 node associated to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` and returns the first node matching the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).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/UiObject2.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#(androidx.test.uiautomator.UiObject2).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 the node associated to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` and returns all the nodes matching the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).onElements(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/UiObject2.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#(androidx.test.uiautomator.UiObject2).scrollToElement(androidx.test.uiautomator.Direction,kotlin.Long,kotlin.Long,kotlin.Function1)( direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction, 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 )` Keeps scrolling until the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).scrollToElement(androidx.test.uiautomator.Direction,kotlin.Long,kotlin.Long,kotlin.Function1)` condition is satisfied or until the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).scrollToElement(androidx.test.uiautomator.Direction,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/UiObject2.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#(androidx.test.uiautomator.UiObject2).scrollToElementOrNull(androidx.test.uiautomator.Direction,kotlin.Long,kotlin.Long,kotlin.Function1)( direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction, 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 )` Keeps scrolling until the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).scrollToElementOrNull(androidx.test.uiautomator.Direction,kotlin.Long,kotlin.Long,kotlin.Function1)` condition is satisfied or until the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).scrollToElementOrNull(androidx.test.uiautomator.Direction,kotlin.Long,kotlin.Long,kotlin.Function1)`. |
| `https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#(androidx.test.uiautomator.UiObject2).takeScreenshot()()` Takes a screenshot of the screen that contains the accessibility node associated to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` and cuts only the area covered by it. |
| `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/StableResult` | `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2.https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2#(androidx.test.uiautomator.UiObject2).waitForStable(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 node to become stable. |

## Public functions

### clear

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

```
fun clear(): Unit
```

Clears this object's text content if it is an editable field.

### click

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

```
fun click(): Unit
```

Clicks on this object's center.

### click

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

```
fun click(duration: Long): Unit
```

Clicks on this object's center for `duration` milliseconds.

### click

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

```
fun click(point: Point): Unit
```

Clicks on a `point` within this object's visible bounds.

| Parameters |
|---|---|
| `point: https://developer.android.com/reference/android/graphics/Point.html` | The point to click (clipped to ensure it is within the visible bounds). |

### click

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

```
fun click(point: Point, duration: Long): Unit
```

Clicks on a `point` within this object's visible bounds.

| Parameters |
|---|---|
| `point: https://developer.android.com/reference/android/graphics/Point.html` | The point to click (clipped to ensure it is within the visible bounds). |
| `duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The click duration in milliseconds. |

### clickAndWait

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

```
fun <U> clickAndWait(condition: EventCondition<U!>, timeout: Long): U!
```

Clicks on this object's center, and waits for a `condition` to be met.

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

### clickAndWait

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

```
fun <U> clickAndWait(point: Point, condition: EventCondition<U!>, timeout: Long): U!
```

Clicks on a `point` within this object's visible bounds, and waits for a `
condition` to be met.

| Parameters |
|---|---|
| `point: https://developer.android.com/reference/android/graphics/Point.html` | The point to click (clipped to ensure it is within the visible bounds). |
| `condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/EventCondition<U!>` | The `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/EventCondition` to wait for. |
| `timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The maximum time in milliseconds to wait for. |

### drag

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

```
fun drag(dest: Point): Unit
```

Drags this object to the specified point.

| Parameters |
|---|---|
| `dest: https://developer.android.com/reference/android/graphics/Point.html` | The end point to drag this object to. |

### drag

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

```
fun drag(dest: Point, speed: Int): Unit
```

Drags this object to the specified point.

| Parameters |
|---|---|
| `dest: https://developer.android.com/reference/android/graphics/Point.html` | The end point to drag this object to. |
| `speed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The speed at which to perform this gesture in pixels per second. |

### equals

```
fun equals(object: Any!): Boolean
```

### findObject

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

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

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

### 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!>
```

Searches all elements under this object and returns those that match the `selector`.

### fling

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

```
fun fling(direction: Direction): Boolean
```

Performs a fling gesture on this object.

| Parameters |
|---|---|
| `direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction` | The direction in which to fling. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the object can still scroll in the given direction. |

### fling

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

```
fun fling(direction: Direction, speed: Int): Boolean
```

Performs a fling gesture on this object.

| Parameters |
|---|---|
| `direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction` | The direction in which to fling. |
| `speed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The speed at which to perform this gesture in pixels per second. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the object can still scroll in the given direction. |

### getAccessibilityNodeInfo

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

```
fun getAccessibilityNodeInfo(): AccessibilityNodeInfo
```

Returns an up-to-date `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html` corresponding to this object's underlying `https://developer.android.com/reference/android/view/View.html`. Note that this method can be expensive as it wait for the device to be idle and tries multiple time to refresh the `https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html`.

### getApplicationPackage

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

```
fun getApplicationPackage(): String!
```

Returns the package name of the app that this object belongs to.

### getChildCount

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

```
fun getChildCount(): Int
```

Returns the number of child elements directly under this object.

### getChildren

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

```
fun getChildren(): (Mutable)List<UiObject2!>
```

Returns a collection of the child elements directly under this object.

### getClassName

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

```
fun getClassName(): String!
```

Returns the class name of this object's underlying `https://developer.android.com/reference/android/view/View.html`.

### getContentDescription

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

```
fun getContentDescription(): String!
```

Returns this object's content description.

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

### getDisplayId

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

```
fun getDisplayId(): Int
```

Returns the ID of the display containing this object.

### getDrawingOrder

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

```
@RequiresApi(value = 24)
fun getDrawingOrder(): Int
```

Returns the drawing order (z-index) of this object relative to its siblings. Higher values are drawn last (i.e. above their siblings).

In some cases, the drawing order is essentially simultaneous, so it is possible for two siblings to return the same value. It is also possible that values will be skipped.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The drawing order of this object relative to its siblings. |

### getHint

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

```
@RequiresApi(value = 26)
fun getHint(): String?
```

Returns the hint text of this object, or null if hint text is not preset.

Hint text is displayed when there's no user input text.

| See also |
|---|---|
| `https://developer.android.com/reference/android/widget/TextView.html#getHint()` |   |

### getParent

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

```
fun getParent(): UiObject2!
```

Returns this object's parent, or `null` if it has no parent.

### getResourceName

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

```
fun getResourceName(): String!
```

Returns the fully qualified resource name for this object's ID.

### getText

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

```
fun getText(): String!
```

Returns this object's text content.

| See also |
|---|---|
| `https://developer.android.com/reference/android/widget/TextView.html#getText()` |   |

### getVisibleBounds

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

```
fun getVisibleBounds(): Rect
```

Returns this object's visible bounds.

### getVisibleCenter

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

```
fun getVisibleCenter(): Point
```

Returns a point in the center of this object's visible bounds.

### hasObject

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

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

Returns `true` if there is a nested element which matches the `selector`.

### hashCode

```
fun hashCode(): Int
```

### isCheckable

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

```
fun isCheckable(): Boolean
```

Returns `true` if this object is checkable.

| See also |
|---|---|
| `https://developer.android.com/reference/android/widget/Checkable.html` |   |

### isChecked

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

```
fun isChecked(): Boolean
```

Returns `true` if this object is checked.

| See also |
|---|---|
| `https://developer.android.com/reference/android/widget/Checkable.html#isChecked()` |   |

### isClickable

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

```
fun isClickable(): Boolean
```

Returns `true` if this object is clickable.

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

### isEnabled

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

```
fun isEnabled(): Boolean
```

Returns `true` if this object is enabled.

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

### isFocusable

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

```
fun isFocusable(): Boolean
```

Returns `true` if this object is focusable.

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

### isFocused

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

```
fun isFocused(): Boolean
```

Returns `true` if this object is focused.

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

### isLongClickable

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

```
fun isLongClickable(): Boolean
```

Returns `true` if this object is long clickable.

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

### isScrollable

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

```
fun isScrollable(): Boolean
```

Returns `true` if this object is scrollable.

### isSelected

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

```
fun isSelected(): Boolean
```

Returns `true` if this object is selected.

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

### longClick

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

```
fun longClick(): Unit
```

Performs a long click on this object's center.

### pinchClose

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

```
fun pinchClose(percent: Float): Unit
```

Performs a pinch close gesture on this object.

| Parameters |
|---|---|
| `percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The size of the pinch as a percentage of this object's size. |

### pinchClose

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

```
fun pinchClose(percent: Float, speed: Int): Unit
```

Performs a pinch close gesture on this object.

| Parameters |
|---|---|
| `percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The size of the pinch as a percentage of this object's size. |
| `speed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The speed at which to perform this gesture in pixels per second. |

### pinchOpen

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

```
fun pinchOpen(percent: Float): Unit
```

Performs a pinch open gesture on this object.

| Parameters |
|---|---|
| `percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The size of the pinch as a percentage of this object's size. |

### pinchOpen

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

```
fun pinchOpen(percent: Float, speed: Int): Unit
```

Performs a pinch open gesture on this object.

| Parameters |
|---|---|
| `percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The size of the pinch as a percentage of this object's size. |
| `speed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The speed at which to perform this gesture in pixels per second. |

### recycle

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

```
fun recycle(): Unit
```

Recycle this object.

### scroll

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

```
fun scroll(direction: Direction, percent: Float): Boolean
```

Performs a scroll gesture on this object.

| Parameters |
|---|---|
| `direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction` | The direction in which to scroll. |
| `percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The distance to scroll as a percentage of this object's visible size. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the object can still scroll in the given direction. |

### scroll

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

```
fun scroll(direction: Direction, percent: Float, speed: Int): Boolean
```

Performs a scroll gesture on this object.

| Parameters |
|---|---|
| `direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction` | The direction in which to scroll. |
| `percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The distance to scroll as a percentage of this object's visible size. |
| `speed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The speed at which to perform this gesture in pixels per second. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the object can still scroll in the given direction. |

### scrollUntil

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

```
fun <U> scrollUntil(direction: Direction, condition: Condition<UiObject2!, U!>): U!
```

Perform scroll actions in certain direction until a `condition` is satisfied or scroll has finished, e.g. to scroll until an object contain certain text is found:

```kotlin
 mScrollableUiObject2.scrollUntil(Direction.DOWN, Until.findObject(By.textContains
("sometext"))); 
```

| Parameters |
|---|---|
| `direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction` | The direction in which to scroll. |
| `condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Condition<https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2!, U!>` | The `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Condition` to evaluate. |

| Returns |
|---|---|
| `U!` | If the condition is satisfied. |

### scrollUntil

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

```
fun <U> scrollUntil(direction: Direction, condition: EventCondition<U!>): U!
```

Perform scroll actions in certain direction until a `condition` is satisfied or scroll has finished, e.g. to scroll until a new window has appeared:

```kotlin
 mScrollableUiObject2.scrollUntil(Direction.DOWN, Until.newWindow()); 
```

| Parameters |
|---|---|
| `direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction` | The direction in which to scroll. |
| `condition: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/EventCondition<U!>` | The `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/EventCondition` to wait for. |

| Returns |
|---|---|
| `U!` | The value obtained after applying the condition. |

### setGestureMargin

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

```
fun setGestureMargin(margin: Int): Unit
```

Sets the margins used for gestures in pixels.

### setGestureMarginPercentage

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

```
fun setGestureMarginPercentage(percent: @FloatRange(from = 0.0, to = 0.5) Float): Unit
```

Sets the percentage of gestures' margins to avoid touching too close to the edges, e.g. when scrolling up, phone open quick settings instead if gesture is close to the top. The percentage is based on the object's visible size, e.g. to set 20% margins:

```kotlin
mUiObject2.setGestureMarginPercentage(0.2f);
```

| Parameters |
|---|---|
| `percent: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | Float between \[0, 0.5\] for four margins: left, top, right, and bottom. |

### setGestureMargins

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

```
fun setGestureMargins(left: Int, top: Int, right: Int, bottom: Int): Unit
```

Sets the margins used for gestures in pixels.

### setGestureMarginsPercentage

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

```
fun setGestureMarginsPercentage(
    left: @FloatRange(from = 0.0, to = 1.0) Float,
    top: @FloatRange(from = 0.0, to = 1.0) Float,
    right: @FloatRange(from = 0.0, to = 1.0) Float,
    bottom: @FloatRange(from = 0.0, to = 1.0) Float
): Unit
```

Sets the percentage of gestures' margins to avoid touching too close to the edges, e.g. when scrolling up, phone open quick settings instead if gesture is close to the top. The percentage is based on the object's visible size, e.g. to set 20% bottom margin only:

```kotlin
mUiObject2.setGestureMarginsPercentage(0f, 0f, 0f, 0.2f);
```

left Float between \[0, 1\] for left margin

top Float between \[0, 1\] for top margin

right Float between \[0, 1\] for right margin

bottom Float between \[0, 1\] for bottom margin

### setText

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

```
fun setText(text: String?): Unit
```

Sets this object's text content if it is an editable field.

### swipe

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

```
fun swipe(direction: Direction, percent: Float): Unit
```

Performs a swipe gesture on this object.

| Parameters |
|---|---|
| `direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction` | The direction in which to swipe. |
| `percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The length of the swipe as a percentage of this object's size. |

### swipe

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

```
fun swipe(direction: Direction, percent: Float, speed: Int): Unit
```

Performs a swipe gesture on this object.

| Parameters |
|---|---|
| `direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction` | The direction in which to swipe. |
| `percent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The length of the swipe as a percentage of this object's size. |
| `speed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The speed at which to perform this gesture in pixels per second. |

### wait

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

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

Waits for a `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/UiObject2!, 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` | The maximum time in milliseconds to wait for. |

| 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 a `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` | The maximum time in milliseconds to wait for. |

| 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: UiObject2Condition<U!>, timeout: Long): U!
```

Waits for a `condition` to be met.

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

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

## Extension functions

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

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

Performs a DFS on the accessibility tree starting from the node associated to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` and returns the first node matching the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).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.UiObject2).onElement(kotlin.Long,kotlin.Long,kotlin.Function1)`.

Example:

```kotlin
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.UiObject2).onElement(kotlin.Long,kotlin.Long,kotlin.Function1)` condition. |

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

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

Performs a DFS on the accessibility tree starting from the node associated to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` and returns the first node matching the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).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.UiObject2).onElementOrNull(kotlin.Long,kotlin.Long,kotlin.Function1)`.

Example:

```kotlin
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.UiObject2).onElementOrNull(kotlin.Long,kotlin.Long,kotlin.Function1)` condition or null. |

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

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

Performs a DFS on the accessibility tree starting from the node associated to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` and returns all the nodes matching the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).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.UiObject2).onElements(kotlin.Long,kotlin.Long,kotlin.Function1)`.

Example:

```kotlin
node.onElements { isClass(Button::class.java) }
```

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.UiObject2).onElements(kotlin.Long,kotlin.Long,kotlin.Function1)` condition. |

### UiObject2.scrollToElement

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/UiObject2Ext.kt+function:scrollToElement)

```
fun UiObject2.scrollToElement(
    direction: Direction,
    timeoutMs: Long = 10000,
    pollIntervalMs: Long = 100,
    block: AccessibilityNodeInfo.() -> Boolean
): UiObject2
```

Keeps scrolling until the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).scrollToElement(androidx.test.uiautomator.Direction,kotlin.Long,kotlin.Long,kotlin.Function1)` condition is satisfied or until the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).scrollToElement(androidx.test.uiautomator.Direction,kotlin.Long,kotlin.Long,kotlin.Function1)`. Throws a `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/ElementNotFoundException` if the condition is not satisfied at the end of the timeout.

Example:

```kotlin
onElement { isScrollable }.scrollToElement(Direction.DOWN) { id == "button" }.click()
```

| Parameters |
|---|---|
| `direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction` | the scroll `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction`. |
| `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` that matches the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).scrollToElement(androidx.test.uiautomator.Direction,kotlin.Long,kotlin.Long,kotlin.Function1)` condition. |

### UiObject2.scrollToElementOrNull

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/UiObject2Ext.kt+function:scrollToElementOrNull)

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

Keeps scrolling until the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).scrollToElementOrNull(androidx.test.uiautomator.Direction,kotlin.Long,kotlin.Long,kotlin.Function1)` condition is satisfied or until the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).scrollToElementOrNull(androidx.test.uiautomator.Direction,kotlin.Long,kotlin.Long,kotlin.Function1)`. Returns null if the condition is not satisfied at the end of the timeout.

Example:

```kotlin
onElement { isScrollable }.scrollToElement(Direction.DOWN) { id == "button" }.click()
```

| Parameters |
|---|---|
| `direction: https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction` | the scroll `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/Direction`. |
| `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` that matches the given `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/package-summary#(androidx.test.uiautomator.UiObject2).scrollToElementOrNull(androidx.test.uiautomator.Direction,kotlin.Long,kotlin.Long,kotlin.Function1)` condition. |

### UiObject2.takeScreenshot

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/UiObject2Ext.kt+function:takeScreenshot)

```
fun UiObject2.takeScreenshot(): Bitmap
```

Takes a screenshot of the screen that contains the accessibility node associated to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2` and cuts only the area covered by it.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html` | a bitmap containing the image of the node associated to this `https://developer.android.com/reference/kotlin/androidx/test/uiautomator/UiObject2`. |

### UiObject2.waitForStable

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/UiObject2Ext.kt+function:waitForStable)

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

Waits for the node 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.

| 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.UiObject2).waitForStable(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. |