to top

UiCollection

Used to enumerate a container's user interface (UI) elements for the purpose of counting, or targeting a sub elements by a child's text or description.

Summary

Public Constructors
UiCollection(UiSelector selector)
Public Methods
UiObject getChildByDescription(UiSelector childPattern, String text)
Searches for child UI element within the constraints of this UiSelector selector.
UiObject getChildByInstance(UiSelector childPattern, int instance)
Searches for child UI element within the constraints of this UiSelector.
UiObject getChildByText(UiSelector childPattern, String text)
Searches for child UI element within the constraints of this UiSelector.
int getChildCount(UiSelector childPattern)
Counts child UI element instances matching the childPattern argument.
[Expand]
Inherited Methods
From class com.android.uiautomator.core.UiObject
From class java.lang.Object

Public Constructors

public UiCollection (UiSelector selector)

Public Methods

public UiObject getChildByDescription (UiSelector childPattern, String text)

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

public UiObject getChildByInstance (UiSelector childPattern, int instance)

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

public UiObject getChildByText (UiSelector childPattern, String text)

Searches for child UI element within the constraints of this UiSelector selector. It looks for any child matching the childPattern argument that has a child UI element anywhere within its sub hierarchy that has a text attribute equal to 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 selector of the child pattern to match and return
text String of the identifying child contents of of the childPattern
Returns
  • UiObject pointing at and instance of childPattern

public 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 a UiSelector that represents the matching child UI elements to count
Returns
  • the number of matched childPattern under the current UiCollection