Skip to content

Most visited

Recently visited

navigation

UiCollection

public class UiCollection
extends UiObject

java.lang.Object
   ↳ android.support.test.uiautomator.UiObject
     ↳ android.support.test.uiautomator.UiCollection
Known Direct Subclasses


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

Inherited constants

From class android.support.test.uiautomator.UiObject

Public constructors

UiCollection(UiSelector selector)

Constructs an instance as described by the selector

Public methods

UiObject getChildByDescription(UiSelector childPattern, String text)

Searches for child UI element within the constraints of this UiCollection UiSelector selector.

UiObject getChildByInstance(UiSelector childPattern, int instance)

Searches for child UI element within the constraints of this UiCollection UiSelector selector.

UiObject getChildByText(UiSelector childPattern, String text)

Searches for child UI element within the constraints of this UiCollection UiSelector selector.

int getChildCount(UiSelector childPattern)

Counts child UI element instances matching the childPattern argument.

Inherited methods

From class android.support.test.uiautomator.UiObject
From class java.lang.Object

Public constructors

UiCollection

UiCollection (UiSelector selector)

Constructs an instance as described by the selector

Public methods

getChildByDescription

UiObject getChildByDescription (UiSelector childPattern, 
                String text)

Searches for child UI element within the constraints of this UiCollection 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
childPattern UiSelector: UiSelector selector of the child pattern to match and return
text String: String of the identifying child contents of of the childPattern
Returns
UiObject UiObject pointing at and instance of childPattern
Throws
UiObjectNotFoundException
UiObjectNotFoundException

getChildByInstance

UiObject getChildByInstance (UiSelector childPattern, 
                int instance)

Searches for child UI element within the constraints of this UiCollection 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
childPattern UiSelector: UiSelector selector of the child pattern to match and return
instance int: int the desired matched instance of this childPattern
Returns
UiObject UiObject pointing at and instance of childPattern
Throws
UiObjectNotFoundException

getChildByText

UiObject getChildByText (UiSelector childPattern, 
                String text)

Searches for child UI element within the constraints of this UiCollection 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
childPattern UiSelector: UiSelector selector of the child pattern to match and return
text String: String of the identifying child contents of of the childPattern
Returns
UiObject UiObject pointing at and instance of childPattern
Throws
UiObjectNotFoundException
UiObjectNotFoundException

getChildCount

int getChildCount (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
childPattern UiSelector: a UiSelector that represents the matching child UI elements to count
Returns
int the number of matched childPattern under the current UiCollection
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.