# UiCollection

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

*** ** * ** ***


```
public class UiCollection extends UiObject
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.test.uiautomator.UiObject](https://developer.android.com/reference/androidx/test/uiautomator/UiObject) ||
|   | ↳ | [androidx.test.uiautomator.UiCollection](https://developer.android.com/reference/androidx/test/uiautomator/UiCollection) |

Known direct 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. |

*** ** * ** ***

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.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/UiCollection#UiCollection(androidx.test.uiautomator.UiSelector)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector selector)` Constructs an instance as described by the selector |

| ### Public methods |
|---|---|
| `@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/UiCollection#getChildByDescription(androidx.test.uiautomator.UiSelector,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector childPattern, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html text )` Searches for child UI element within the constraints of this UiCollection `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` selector. |
| `@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/UiCollection#getChildByInstance(androidx.test.uiautomator.UiSelector,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector childPattern, int instance)` Searches for child UI element within the constraints of this UiCollection `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` selector. |
| `@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/UiCollection#getChildByText(androidx.test.uiautomator.UiSelector,java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector childPattern, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html text)` Searches for child UI element within the constraints of this UiCollection `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` selector. |
| `int` | `https://developer.android.com/reference/androidx/test/uiautomator/UiCollection#getChildCount(androidx.test.uiautomator.UiSelector)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector childPattern)` Counts child UI element instances matching the `childPattern` argument. |

| ### Inherited Constants |
|---|
| From [androidx.test.uiautomator.UiObject](https://developer.android.com/reference/androidx/test/uiautomator/UiObject) |---|---| | `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` | |

| ### Inherited methods |
|---|
| From [androidx.test.uiautomator.UiObject](https://developer.android.com/reference/androidx/test/uiautomator/UiObject) |---|---| | `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/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. | | `@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. | |

## Public constructors

### UiCollection

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

```
public UiCollection(@NonNull UiSelector selector)
```

Constructs an instance as described by the selector

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

## Public methods

### getChildByDescription

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

```
public @NonNull UiObject getChildByDescription(
    @NonNull UiSelector childPattern,
    @NonNull String text
)
```

Searches for child UI element within the constraints of this UiCollection `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` selector. It looks for any child matching the `childPattern` argument that has a child UI element anywhere within its sub hierarchy that has content-description text. The returned UiObject will point at the `childPattern` instance that matched the search and not at the identifying child element that matched the content description.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector childPattern` | `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` selector of the child pattern to match and return |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html text` | String of the identifying child contents of of the `childPattern` |

| Returns |
|---|---|
| `@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` pointing at and instance of `childPattern` |

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

### getChildByInstance

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

```
public @NonNull UiObject getChildByInstance(@NonNull UiSelector childPattern, int instance)
```

Searches for child UI element within the constraints of this UiCollection `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` selector. It looks for any child matching the `childPattern` argument that has a child UI element anywhere within its sub hierarchy that is at the `instance` specified. The operation is performed only on the visible items and no scrolling is performed in this case.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector childPattern` | `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` selector of the child pattern to match and return |
| `int instance` | int the desired matched instance of this `childPattern` |

| Returns |
|---|---|
| `@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` pointing at and instance of `childPattern` |

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

### getChildByText

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

```
public @NonNull UiObject getChildByText(@NonNull UiSelector childPattern, @NonNull String text)
```

Searches for child UI element within the constraints of this UiCollection `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` selector. It looks for any child matching the `childPattern` argument that has a child UI element anywhere within its sub hierarchy that has text attribute = `text`. The returned UiObject will point at the `childPattern` instance that matched the search and not at the identifying child element that matched the text attribute.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector childPattern` | `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` selector of the child pattern to match and return |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html text` | String of the identifying child contents of of the `childPattern` |

| Returns |
|---|---|
| `@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` pointing at and instance of `childPattern` |

| 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(@NonNull UiSelector childPattern)
```

Counts child UI element instances matching the `childPattern` argument. The method returns the number of matching UI elements that are currently visible. The count does not include items of a scrollable list that are off-screen.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiSelector childPattern` | a `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector` that represents the matching child UI elements to count |

| Returns |
|---|---|
| `int` | the number of matched childPattern under the current `https://developer.android.com/reference/androidx/test/uiautomator/UiCollection` |