public class

BySelector

extends Object
java.lang.Object
   ↳ android.support.test.uiautomator.BySelector

Class Overview

A BySelector specifies criteria for matching UI elements during a call to findObject(BySelector).

Summary

Public Methods
BySelector checkable(boolean isCheckable)
Sets the search criteria to match elements that are checkable or not checkable.
BySelector checked(boolean isChecked)
Sets the search criteria to match elements that are checked or unchecked.
BySelector clazz(Pattern className)
Sets the class name criteria for matching.
BySelector clazz(String className)
Sets the class name criteria for matching.
BySelector clazz(Class clazz)
Sets the class name criteria for matching.
BySelector clazz(String packageName, String className)
Sets the class name criteria for matching.
BySelector clickable(boolean isClickable)
Sets the search criteria to match elements that are clickable or not clickable.
BySelector depth(int exactDepth)
Sets the search criteria to match elements that are at a certain depth.
BySelector depth(int min, int max)
Sets the search criteria to match elements that are in a range of depths.
BySelector desc(Pattern contentDescription)
Sets the content description criteria for matching.
BySelector desc(String contentDescription)
Sets the content description criteria for matching.
BySelector descContains(String substring)
Sets the content description criteria for matching.
BySelector descEndsWith(String substring)
Sets the content description criteria for matching.
BySelector descStartsWith(String substring)
Sets the content description criteria for matching.
BySelector enabled(boolean isEnabled)
Sets the search criteria to match elements that are enabled or disabled.
BySelector focusable(boolean isFocusable)
Sets the search criteria to match elements that are focusable or not focusable.
BySelector focused(boolean isFocused)
Sets the search criteria to match elements that are focused or unfocused.
BySelector hasChild(BySelector childSelector)
Adds a child selector criteria for matching.
BySelector hasDescendant(BySelector descendantSelector, int maxDepth)
Adds a descendant selector criteria for matching.
BySelector hasDescendant(BySelector descendantSelector)
Adds a descendant selector criteria for matching.
BySelector longClickable(boolean isLongClickable)
Sets the search criteria to match elements that are long clickable or not long clickable.
BySelector maxDepth(int max)
Sets the search criteria to match elements that are no more than a certain depth.
BySelector minDepth(int min)
Sets the search criteria to match elements that are at least a certain depth.
BySelector pkg(String applicationPackage)
Sets the application package name criteria for matching.
BySelector pkg(Pattern applicationPackage)
Sets the package name criteria for matching.
BySelector res(String resourceName)
Sets the resource name criteria for matching.
BySelector res(Pattern resourceName)
Sets the resource name criteria for matching.
BySelector res(String resourcePackage, String resourceId)
Sets the resource name criteria for matching.
BySelector scrollable(boolean isScrollable)
Sets the search criteria to match elements that are scrollable or not scrollable.
BySelector selected(boolean isSelected)
Sets the search criteria to match elements that are selected or not selected.
BySelector text(Pattern textValue)
Sets the text value criteria for matching.
BySelector text(String textValue)
Sets the text value criteria for matching.
BySelector textContains(String substring)
Sets the text value criteria for matching.
BySelector textEndsWith(String substring)
Sets the text value criteria for matching.
BySelector textStartsWith(String substring)
Sets the text value criteria for matching.
String toString()
Returns a String representation of this BySelector.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public BySelector checkable (boolean isCheckable)

Sets the search criteria to match elements that are checkable or not checkable.

Parameters
isCheckable Whether to match elements that are checkable or elements that are not checkable.
Returns

public BySelector checked (boolean isChecked)

Sets the search criteria to match elements that are checked or unchecked.

Parameters
isChecked Whether to match elements that are checked or elements that are unchecked.
Returns

public BySelector clazz (Pattern className)

Sets the class name criteria for matching. A UI element will be considered a match if its full class name matches the className Pattern and all other criteria for this selector are met.

Parameters
className The Pattern to be used for matching.
Returns

public BySelector clazz (String className)

Sets the class name criteria for matching. A UI element will be considered a match if its class name exactly matches the className parameter and all other criteria for this selector are met. If className starts with a period, it is assumed to be in the android.widget package.

Parameters
className The full class name value to match.
Returns

public BySelector clazz (Class clazz)

Sets the class name criteria for matching. A UI element will be considered a match if its class name matches clazz and all other criteria for this selector are met.

Parameters
clazz The class to match.
Returns

public BySelector clazz (String packageName, String className)

Sets the class name criteria for matching. A UI element will be considered a match if its package and class name exactly match the packageName and className parameters and all other criteria for this selector are met.

Parameters
packageName The package value to match.
className The class name value to match.
Returns

public BySelector clickable (boolean isClickable)

Sets the search criteria to match elements that are clickable or not clickable.

Parameters
isClickable Whether to match elements that are clickable or elements that are not clickable.
Returns

public BySelector depth (int exactDepth)

Sets the search criteria to match elements that are at a certain depth.

public BySelector depth (int min, int max)

Sets the search criteria to match elements that are in a range of depths.

public BySelector desc (Pattern contentDescription)

Sets the content description criteria for matching. A UI element will be considered a match if its content description matches the contentDescription Pattern and all other criteria for this selector are met.

Parameters
contentDescription The Pattern to be used for matching.
Returns

public BySelector desc (String contentDescription)

Sets the content description criteria for matching. A UI element will be considered a match if its content description exactly matches the contentDescription parameter and all other criteria for this selector are met.

Parameters
contentDescription The exact value to match.
Returns

public BySelector descContains (String substring)

Sets the content description criteria for matching. A UI element will be considered a match if its content description contains the substring parameter and all other criteria for this selector are met.

Parameters
substring The substring to match.
Returns

public BySelector descEndsWith (String substring)

Sets the content description criteria for matching. A UI element will be considered a match if its content description ends with the substring parameter and all other criteria for this selector are met.

Parameters
substring The substring to match.
Returns

public BySelector descStartsWith (String substring)

Sets the content description criteria for matching. A UI element will be considered a match if its content description starts with the substring parameter and all other criteria for this selector are met.

Parameters
substring The substring to match.
Returns

public BySelector enabled (boolean isEnabled)

Sets the search criteria to match elements that are enabled or disabled.

Parameters
isEnabled Whether to match elements that are enabled or elements that are disabled.
Returns

public BySelector focusable (boolean isFocusable)

Sets the search criteria to match elements that are focusable or not focusable.

Parameters
isFocusable Whether to match elements that are focusable or elements that are not focusable.
Returns

public BySelector focused (boolean isFocused)

Sets the search criteria to match elements that are focused or unfocused.

Parameters
isFocused Whether to match elements that are focused or elements that are unfocused.
Returns

public BySelector hasChild (BySelector childSelector)

Adds a child selector criteria for matching. A UI element will be considered a match if it has a child element (direct descendant) which matches the childSelector and all other criteria for this selector are met. If specified more than once, matches must be found for all childSelectors.

Parameters
childSelector The selector used to find a matching child element.
Returns

public BySelector hasDescendant (BySelector descendantSelector, int maxDepth)

Adds a descendant selector criteria for matching. A UI element will be considered a match if it has a descendant element which matches the descendantSelector and all other criteria for this selector are met. If specified more than once, matches must be found for all descendantSelectors.

Parameters
descendantSelector The selector used to find a matching descendant element.
maxDepth The maximum depth under the element to search the descendant.
Returns

public BySelector hasDescendant (BySelector descendantSelector)

Adds a descendant selector criteria for matching. A UI element will be considered a match if it has a descendant element which matches the descendantSelector and all other criteria for this selector are met. If specified more than once, matches must be found for all descendantSelectors.

Parameters
descendantSelector The selector used to find a matching descendant element.
Returns

public BySelector longClickable (boolean isLongClickable)

Sets the search criteria to match elements that are long clickable or not long clickable.

Parameters
isLongClickable Whether to match elements that are long clickable or elements that are not long clickable.
Returns

public BySelector maxDepth (int max)

Sets the search criteria to match elements that are no more than a certain depth.

public BySelector minDepth (int min)

Sets the search criteria to match elements that are at least a certain depth.

public BySelector pkg (String applicationPackage)

Sets the application package name criteria for matching. A UI element will be considered a match if its application package name exactly matches the applicationPackage parameter and all other criteria for this selector are met.

Parameters
applicationPackage The exact value to match.
Returns

public BySelector pkg (Pattern applicationPackage)

Sets the package name criteria for matching. A UI element will be considered a match if its application package name matches the applicationPackage Pattern and all other criteria for this selector are met.

Parameters
applicationPackage The Pattern to be used for matching.
Returns

public BySelector res (String resourceName)

Sets the resource name criteria for matching. A UI element will be considered a match if its resource name exactly matches the resourceName parameter and all other criteria for this selector are met.

Parameters
resourceName The exact value to match.
Returns

public BySelector res (Pattern resourceName)

Sets the resource name criteria for matching. A UI element will be considered a match if its resource name matches the resourceName Pattern and all other criteria for this selector are met.

Parameters
resourceName The Pattern to be used for matching.
Returns

public BySelector res (String resourcePackage, String resourceId)

Sets the resource name criteria for matching. A UI element will be considered a match if its resource package and resource id exactly match the resourcePackage and resourceId parameters and all other criteria for this selector are met.

Parameters
resourcePackage The resource package value to match.
resourceId The resouce-id value to match.
Returns

public BySelector scrollable (boolean isScrollable)

Sets the search criteria to match elements that are scrollable or not scrollable.

Parameters
isScrollable Whether to match elements that are scrollable or elements that are not scrollable.
Returns

public BySelector selected (boolean isSelected)

Sets the search criteria to match elements that are selected or not selected.

Parameters
isSelected Whether to match elements that are selected or elements that are not selected.
Returns

public BySelector text (Pattern textValue)

Sets the text value criteria for matching. A UI element will be considered a match if its text value matches the textValue Pattern and all other criteria for this selector are met.

Parameters
textValue The Pattern to be used for matching.
Returns

public BySelector text (String textValue)

Sets the text value criteria for matching. A UI element will be considered a match if its text value exactly matches the textValue parameter and all other criteria for this selector are met.

Parameters
textValue The exact value to match.
Returns

public BySelector textContains (String substring)

Sets the text value criteria for matching. A UI element will be considered a match if its text value contains the substring parameter and all other criteria for this selector are met.

Parameters
substring The substring to match.
Returns

public BySelector textEndsWith (String substring)

Sets the text value criteria for matching. A UI element will be considered a match if its text value ends with the substring parameter and all other criteria for this selector are met.

Parameters
substring The substring to match.
Returns

public BySelector textStartsWith (String substring)

Sets the text value criteria for matching. A UI element will be considered a match if its text value starts with the substring parameter and all other criteria for this selector are met.

Parameters
substring The substring to match.
Returns

public String toString ()

Returns a String representation of this BySelector. The format is "BySelector [<KEY>='<VALUE> ... ]". Each criteria is listed as a key-value pair where the key is the name of the criteria expressed in all caps (e.g. CLAZZ, RES, etc).