# UiObject

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

*** ** * ** ***


```
public class UiObject
```

<br />

Known direct subclasses [UiCollection](https://developer.android.com/reference/androidx/test/uiautomator/UiCollection)

|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiCollection` | Used to enumerate a container's UI elements for the purpose of counting, or targeting a sub elements by a child's text or description. |

Known indirect subclasses [UiScrollable](https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable)

|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable` | UiScrollable is a `https://developer.android.com/reference/androidx/test/uiautomator/UiCollection` and provides support for searching for items in scrollable layout elements. |

*** ** * ** ***

A UiObject is a representation of a view. It is not in any way directly bound to a view as an object reference. A UiObject contains information to help it locate a matching view at runtime based on the `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` properties specified in its constructor. Once you create an instance of a UiObject, it can be reused for different views that match the selector criteria.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#FINGER_TOUCH_HALF_WIDTH() = 20` |
| `static final int` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#SWIPE_MARGIN_LIMIT() = 5` |
| `static final long` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#WAIT_FOR_EVENT_TMEOUT() = 3000` **This field is deprecated.** use `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setScrollAcknowledgmentTimeout(long)` <br /> |
| `static final long` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#WAIT_FOR_SELECTOR_POLL() = 1000` |
| `static final long` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#WAIT_FOR_SELECTOR_TIMEOUT() = 10000` **This field is deprecated.** use `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setWaitForSelectorTimeout(long)` <br /> |
| `static final long` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#WAIT_FOR_WINDOW_TMEOUT() = 5500` |

| ### Public constructors |
|---|
| `[UiObject](https://developer.android.com/reference/androidx/test/uiautomator/UiObject#UiObject(androidx.test.uiautomator.UiSelector))(https://developer.android.com/reference/androidx/test/uiautomator/UiSelector selector)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/test/uiautomator/UiDevice#findObject(androidx.test.uiautomator.UiSelector)` instead. <br /> |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#clearTextField()()` Clears the existing text contents in an editable field. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#click()()` Performs a click at the center of the visible bounds of the UI element represented by this UiObject. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#clickAndWaitForNewWindow()()` Waits for window transitions that would typically take longer than the usual default timeouts. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#clickAndWaitForNewWindow(long)(long timeout)` Performs a click at the center of the visible bounds of the UI element represented by this UiObject and waits for window transitions. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#clickBottomRight()()` Clicks the bottom and right corner of the UI element |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#clickTopLeft()()` Clicks the top and left corner of the UI element |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#dragTo(androidx.test.uiautomator.UiObject,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiObject destObj, int steps)` Drags this object to a destination UiObject. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#dragTo(int,int,int)(int destX, int destY, int steps)` Drags this object to arbitrary coordinates. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#exists()()` Check if view exists. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getBounds()()` Returns the view's `bounds` property. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiObject` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getChild(androidx.test.uiautomator.UiSelector)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector selector)` Creates a new UiObject for a child view that is under the present UiObject. |
| `int` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getChildCount()()` Counts the child views immediately under the present UiObject. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getClassName()()` Retrieves the `className` property of the UI element. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getContentDescription()()` Reads the `content_desc` property of the UI element |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiObject` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getFromParent(androidx.test.uiautomator.UiSelector)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector selector)` Creates a new UiObject for a sibling view or a child of the sibling view, relative to the present UiObject. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getPackageName()()` Reads the view's `package` property |
| `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getSelector()()` Debugging helper. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getText()()` Reads the `text` property of the UI element |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getVisibleBounds()()` Returns the visible bounds of the view. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#isCheckable()()` Checks if the UI element's `checkable` property is currently true. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#isChecked()()` Check if the UI element's `checked` property is currently true |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#isClickable()()` Checks if the UI element's `clickable` property is currently true. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#isEnabled()()` Checks if the UI element's `enabled` property is currently true. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#isFocusable()()` Check if the UI element's `focusable` property is currently true. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#isFocused()()` Check if the UI element's `focused` property is currently true |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#isLongClickable()()` Check if the view's `long-clickable` property is currently true |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#isScrollable()()` Check if the view's `scrollable` property is currently true |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#isSelected()()` Checks if the UI element's `selected` property is currently true. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#longClick()()` Long clicks the center of the visible bounds of the UI element |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#longClickBottomRight()()` Long clicks bottom and right corner of the UI element |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#longClickTopLeft()()` Long clicks on the top and left corner of the UI element |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#performMultiPointerGesture(android.view.MotionEvent.PointerCoords[]...)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html MotionEvent.PointerCoords[][] touches )` Performs a multi-touch gesture. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#performTwoPointerGesture(android.graphics.Point,android.graphics.Point,android.graphics.Point,android.graphics.Point,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Point.html startPoint1, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Point.html startPoint2, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Point.html endPoint1, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Point.html endPoint2, int steps )` Generates a two-pointer gesture with arbitrary starting and ending points. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#pinchIn(int,int)(int percent, int steps)` Performs a two-pointer gesture, where each pointer moves diagonally toward the other, from the edges to the center of this UiObject . |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#pinchOut(int,int)(int percent, int steps)` Performs a two-pointer gesture, where each pointer moves diagonally opposite across the other, from the center out towards the edges of the this UiObject. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#setText(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html text)` Sets the text in an editable field, after clearing the field's content. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#swipeDown(int)(int steps)` Performs the swipe down action on the UiObject. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#swipeLeft(int)(int steps)` Performs the swipe left action on the UiObject. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#swipeRight(int)(int steps)` Performs the swipe right action on the UiObject. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#swipeUp(int)(int steps)` Performs the swipe up action on the UiObject. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#waitForExists(long)(long timeout)` Waits a specified length of time for a view to become visible. |
| `boolean` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#waitUntilGone(long)(long timeout)` Waits a specified length of time for a view to become undetectable. |

| ### Protected methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html` | `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#findAccessibilityNodeInfo(long)(long timeout)` Finds a matching UI element in the accessibility hierarchy, by using the selector for this UiObject. |

## Constants

### FINGER_TOUCH_HALF_WIDTH

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

```
protected static final int FINGER_TOUCH_HALF_WIDTH = 20
```

### SWIPE_MARGIN_LIMIT

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

```
protected static final int SWIPE_MARGIN_LIMIT = 5
```

### WAIT_FOR_EVENT_TMEOUT

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)

```
protected static final long WAIT_FOR_EVENT_TMEOUT = 3000
```

> [!CAUTION]
> **This field is deprecated.**   
>
> use `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setScrollAcknowledgmentTimeout(long)`

### WAIT_FOR_SELECTOR_POLL

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

```
protected static final long WAIT_FOR_SELECTOR_POLL = 1000
```

### WAIT_FOR_SELECTOR_TIMEOUT

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)

```
protected static final long WAIT_FOR_SELECTOR_TIMEOUT = 10000
```

> [!CAUTION]
> **This field is deprecated.**   
>
> use `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setWaitForSelectorTimeout(long)`

### WAIT_FOR_WINDOW_TMEOUT

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

```
protected static final long WAIT_FOR_WINDOW_TMEOUT = 5500
```

## Public constructors

### UiObject

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)

```
public [UiObject](https://developer.android.com/reference/androidx/test/uiautomator/UiObject#UiObject(androidx.test.uiautomator.UiSelector))(UiSelector selector)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/test/uiautomator/UiDevice#findObject(androidx.test.uiautomator.UiSelector)` instead. This version hides UiObject's dependency on UiDevice and is prone to misuse.

Constructs a UiObject to represent a view that matches the specified selector criteria.

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

## Public methods

### clearTextField

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

```
public void clearTextField()
```

Clears the existing text contents in an editable field. The `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` of this object must reference a UI element that is editable. When you call this method, the method sets focus on the editable field, selects all of its existing content, and clears it by sending a DELETE key press

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### click

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

```
public boolean click()
```

Performs a click at the center of the visible bounds of the UI element represented by this UiObject.

| Returns |
|---|---|
| `boolean` | true id successful else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### clickAndWaitForNewWindow

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

```
public boolean clickAndWaitForNewWindow()
```

Waits for window transitions that would typically take longer than the usual default timeouts. See `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#clickAndWaitForNewWindow(long)`

| Returns |
|---|---|
| `boolean` | true if the event was triggered, else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### clickAndWaitForNewWindow

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

```
public boolean clickAndWaitForNewWindow(long timeout)
```

Performs a click at the center of the visible bounds of the UI element represented by this UiObject and waits for window transitions. This method differ from `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#click()` only in that this method waits for a a new window transition as a result of the click. Some examples of a window transition:

- launching a new activity
- bringing up a pop-up menu
- bringing up a dialog

| Parameters |
|---|---|
| `long timeout` | timeout before giving up on waiting for a new window |

| Returns |
|---|---|
| `boolean` | true if the event was triggered, else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### clickBottomRight

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

```
public boolean clickBottomRight()
```

Clicks the bottom and right corner of the UI element

| Returns |
|---|---|
| `boolean` | true on success |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### clickTopLeft

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

```
public boolean clickTopLeft()
```

Clicks the top and left corner of the UI element

| Returns |
|---|---|
| `boolean` | true on success |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### dragTo

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

```
public boolean dragTo(@NonNull UiObject destObj, int steps)
```

Drags this object to a destination UiObject. The number of steps specified in your input parameter can influence the drag speed, and varying speeds may impact the results. Consider evaluating different speeds when using this method in your tests.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiObject destObj` | the destination UiObject. |
| `int steps` | usually 40 steps. You can increase or decrease the steps to change the speed. |

| Returns |
|---|---|
| `boolean` | true if successful |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### dragTo

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

```
public boolean dragTo(int destX, int destY, int steps)
```

Drags this object to arbitrary coordinates. The number of steps specified in your input parameter can influence the drag speed, and varying speeds may impact the results. Consider evaluating different speeds when using this method in your tests.

| Parameters |
|---|---|
| `int destX` | the X-axis coordinate. |
| `int destY` | the Y-axis coordinate. |
| `int steps` | usually 40 steps. You can increase or decrease the steps to change the speed. |

| Returns |
|---|---|
| `boolean` | true if successful |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### exists

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

```
public boolean exists()
```

Check if view exists. This methods performs a `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#waitForExists(long)` with zero timeout. This basically returns immediately whether the view represented by this UiObject exists or not. If you need to wait longer for this view, then see `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#waitForExists(long)`.

| Returns |
|---|---|
| `boolean` | true if the view represented by this UiObject does exist |

### getBounds

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

```
public @NonNull Rect getBounds()
```

Returns the view's `bounds` property. See `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getVisibleBounds()`

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Rect.html` | Rect |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### getChild

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

```
public @NonNull UiObject getChild(@NonNull UiSelector selector)
```

Creates a new UiObject for a child view that is under the present UiObject.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector selector` | for child view to match |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiObject` | a new UiObject representing the child view |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### getChildCount

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

```
public int getChildCount()
```

Counts the child views immediately under the present UiObject.

| Returns |
|---|---|
| `int` | the count of child views. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### getClassName

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

```
public @NonNull String getClassName()
```

Retrieves the `className` property of the UI element.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | class name of the current node represented by this UiObject |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` | if no match was found |

### getContentDescription

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

```
public @NonNull String getContentDescription()
```

Reads the `content_desc` property of the UI element

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | value of node attribute "content_desc" |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### getFromParent

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

```
public @NonNull UiObject getFromParent(@NonNull UiSelector selector)
```

Creates a new UiObject for a sibling view or a child of the sibling view, relative to the present UiObject.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector selector` | for a sibling view or children of the sibling view |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiObject` | a new UiObject representing the matched view |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### getPackageName

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

```
public @NonNull String getPackageName()
```

Reads the view's `package` property

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | true if it is else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### getSelector

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

```
public final @NonNull UiSelector getSelector()
```

Debugging helper. A test can dump the properties of a selector as a string to its logs if needed. `getSelector().toString();`

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

### getText

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

```
public @NonNull String getText()
```

Reads the `text` property of the UI element

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | text value of the current node represented by this UiObject |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` | if no match could be found |

### getVisibleBounds

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

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

Returns the visible bounds of the view. If a portion of the view is visible, only the bounds of the visible portion are reported.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Rect.html` | Rect |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getBounds()` |   |

### isCheckable

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

```
public boolean isCheckable()
```

Checks if the UI element's `checkable` property is currently true.

| Returns |
|---|---|
| `boolean` | true if it is else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### isChecked

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

```
public boolean isChecked()
```

Check if the UI element's `checked` property is currently true

| Returns |
|---|---|
| `boolean` | true if it is else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### isClickable

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

```
public boolean isClickable()
```

Checks if the UI element's `clickable` property is currently true.

| Returns |
|---|---|
| `boolean` | true if it is else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### isEnabled

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

```
public boolean isEnabled()
```

Checks if the UI element's `enabled` property is currently true.

| Returns |
|---|---|
| `boolean` | true if it is else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### isFocusable

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

```
public boolean isFocusable()
```

Check if the UI element's `focusable` property is currently true.

| Returns |
|---|---|
| `boolean` | true if it is else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### isFocused

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

```
public boolean isFocused()
```

Check if the UI element's `focused` property is currently true

| Returns |
|---|---|
| `boolean` | true if it is else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### isLongClickable

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

```
public boolean isLongClickable()
```

Check if the view's `long-clickable` property is currently true

| Returns |
|---|---|
| `boolean` | true if it is else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### isScrollable

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

```
public boolean isScrollable()
```

Check if the view's `scrollable` property is currently true

| Returns |
|---|---|
| `boolean` | true if it is else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### isSelected

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

```
public boolean isSelected()
```

Checks if the UI element's `selected` property is currently true.

| Returns |
|---|---|
| `boolean` | true if it is else false |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### longClick

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

```
public boolean longClick()
```

Long clicks the center of the visible bounds of the UI element

| Returns |
|---|---|
| `boolean` | true if operation was successful |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### longClickBottomRight

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

```
public boolean longClickBottomRight()
```

Long clicks bottom and right corner of the UI element

| Returns |
|---|---|
| `boolean` | true if operation was successful |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### longClickTopLeft

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

```
public boolean longClickTopLeft()
```

Long clicks on the top and left corner of the UI element

| Returns |
|---|---|
| `boolean` | true if operation was successful |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### performMultiPointerGesture

```
public boolean performMultiPointerGesture(
    @NonNull MotionEvent.PointerCoords[][] touches
)
```

Performs a multi-touch gesture. You must specify touch coordinates for at least 2 pointers. Each pointer must have all of its touch steps defined in an array of `https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html`. You can use this method to specify complex gestures, like circles and irregular shapes, where each pointer may take a different path. To create a single point on a pointer's touch path: `
PointerCoords p = new PointerCoords();
p.x = stepX;
p.y = stepY;
p.pressure = 1;
p.size = 1;
`

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html MotionEvent.PointerCoords[][] touches` | represents the pointers' paths. Each `https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html` array represents a different pointer. Each `https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html` in an array element represents a touch point on a pointer's path. |

| Returns |
|---|---|
| `boolean` | `true` if all touch events for this gesture are injected successfully, `false` otherwise |

### performTwoPointerGesture

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

```
public boolean performTwoPointerGesture(
    @NonNull Point startPoint1,
    @NonNull Point startPoint2,
    @NonNull Point endPoint1,
    @NonNull Point endPoint2,
    int steps
)
```

Generates a two-pointer gesture with arbitrary starting and ending points.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Point.html startPoint1` | start point of pointer 1 |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Point.html startPoint2` | start point of pointer 2 |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Point.html endPoint1` | end point of pointer 1 |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Point.html endPoint2` | end point of pointer 2 |
| `int steps` | the number of steps for the gesture. Steps are injected about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete. |

| Returns |
|---|---|
| `boolean` | `true` if all touch events for this gesture are injected successfully, `false` otherwise |

### pinchIn

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

```
public boolean pinchIn(int percent, int steps)
```

Performs a two-pointer gesture, where each pointer moves diagonally toward the other, from the edges to the center of this UiObject .

| Parameters |
|---|---|
| `int percent` | percentage of the object's diagonal length for the pinch gesture |
| `int steps` | the number of steps for the gesture. Steps are injected about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete. |

| Returns |
|---|---|
| `boolean` | `true` if all touch events for this gesture are injected successfully, `false` otherwise |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### pinchOut

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

```
public boolean pinchOut(int percent, int steps)
```

Performs a two-pointer gesture, where each pointer moves diagonally opposite across the other, from the center out towards the edges of the this UiObject.

| Parameters |
|---|---|
| `int percent` | percentage of the object's diagonal length for the pinch gesture |
| `int steps` | the number of steps for the gesture. Steps are injected about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete. |

| Returns |
|---|---|
| `boolean` | `true` if all touch events for this gesture are injected successfully, `false` otherwise |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### setText

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

```
public boolean setText(@Nullable String text)
```

Sets the text in an editable field, after clearing the field's content.

The `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` selector of this object must reference a UI element that is editable.

When you call this method, the method sets focus on the editable field, clears its existing content, then injects your specified text into the field.

If you want to capture the original contents of the field, call `https://developer.android.com/reference/androidx/test/uiautomator/UiObject#getText()` first. You can then modify the text and use this method to update the field.

**Improvements:** Post API Level 19 (KitKat release), the underlying implementation is updated to a dedicated set text accessibility action, and it also now supports Unicode.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html text` | string to set |

| Returns |
|---|---|
| `boolean` | true if operation is successful |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### swipeDown

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

```
public boolean swipeDown(int steps)
```

Performs the swipe down action on the UiObject. The swipe gesture can be performed over any surface. The targeted UI element does not need to be scrollable. See also:

- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollToBeginning(int)`
- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollToEnd(int)`
- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollBackward()`
- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollForward()`

| Parameters |
|---|---|
| `int steps` | indicates the number of injected move steps into the system. Steps are injected about the length of a frame apart (throttled by VSync). |

| Returns |
|---|---|
| `boolean` | true if successful |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### swipeLeft

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

```
public boolean swipeLeft(int steps)
```

Performs the swipe left action on the UiObject. The swipe gesture can be performed over any surface. The targeted UI element does not need to be scrollable. See also:

- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollToBeginning(int)`
- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollToEnd(int)`
- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollBackward()`
- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollForward()`

| Parameters |
|---|---|
| `int steps` | indicates the number of injected move steps into the system. Steps are injected about the length of a frame apart (throttled by VSync). |

| Returns |
|---|---|
| `boolean` | true if successful |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### swipeRight

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

```
public boolean swipeRight(int steps)
```

Performs the swipe right action on the UiObject. The swipe gesture can be performed over any surface. The targeted UI element does not need to be scrollable. See also:

- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollToBeginning(int)`
- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollToEnd(int)`
- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollBackward()`
- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollForward()`

| Parameters |
|---|---|
| `int steps` | indicates the number of injected move steps into the system. Steps are injected about the length of a frame apart (throttled by VSync). |

| Returns |
|---|---|
| `boolean` | true if successful |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### swipeUp

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

```
public boolean swipeUp(int steps)
```

Performs the swipe up action on the UiObject. See also:

- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollToBeginning(int)`
- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollToEnd(int)`
- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollBackward()`
- `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable#scrollForward()`

| Parameters |
|---|---|
| `int steps` | indicates the number of injected move steps into the system. Steps are injected about the length of a frame apart (throttled by VSync). |

| Returns |
|---|---|
| `boolean` | true of successful |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiObjectNotFoundException` |   |

### waitForExists

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

```
public boolean waitForExists(long timeout)
```

Waits a specified length of time for a view to become visible. This method waits until the view becomes visible on the display, or until the timeout has elapsed. You can use this method in situations where the content that you want to select is not immediately displayed.

| Parameters |
|---|---|
| `long timeout` | the amount of time to wait (in milliseconds) |

| Returns |
|---|---|
| `boolean` | true if the view is displayed, else false if timeout elapsed while waiting |

### waitUntilGone

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

```
public boolean waitUntilGone(long timeout)
```

Waits a specified length of time for a view to become undetectable. This method waits until a view is no longer matchable, or until the timeout has elapsed. A view becomes undetectable when the `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` of the object is unable to find a match because the element has either changed its state or is no longer displayed. You can use this method when attempting to wait for some long operation to compete, such as downloading a large file or connecting to a remote server.

| Parameters |
|---|---|
| `long timeout` | time to wait (in milliseconds) |

| Returns |
|---|---|
| `boolean` | true if the element is gone before timeout elapsed, else false if timeout elapsed but a matching element is still found. |

## Protected methods

### findAccessibilityNodeInfo

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

```
protected @Nullable AccessibilityNodeInfo findAccessibilityNodeInfo(long timeout)
```

Finds a matching UI element in the accessibility hierarchy, by using the selector for this UiObject.

| Parameters |
|---|---|
| `long timeout` | in milliseconds |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html` | AccessibilityNodeInfo if found else null |