FileDocCategorySizeDatePackage
UiSelector.javaAPI DocAndroid 5.1 API37497Thu Mar 12 22:22:08 GMT 2015com.android.uiautomator.core

UiSelector

public class UiSelector extends Object
Specifies the elements in the layout hierarchy for tests to target, filtered by properties such as text value, content-description, class name, and state information. You can also target an element by its location in a layout hierarchy.
since
API Level 16

Fields Summary
static final int
SELECTOR_NIL
static final int
SELECTOR_TEXT
static final int
SELECTOR_START_TEXT
static final int
SELECTOR_CONTAINS_TEXT
static final int
SELECTOR_CLASS
static final int
SELECTOR_DESCRIPTION
static final int
SELECTOR_START_DESCRIPTION
static final int
SELECTOR_CONTAINS_DESCRIPTION
static final int
SELECTOR_INDEX
static final int
SELECTOR_INSTANCE
static final int
SELECTOR_ENABLED
static final int
SELECTOR_FOCUSED
static final int
SELECTOR_FOCUSABLE
static final int
SELECTOR_SCROLLABLE
static final int
SELECTOR_CLICKABLE
static final int
SELECTOR_CHECKED
static final int
SELECTOR_SELECTED
static final int
SELECTOR_ID
static final int
SELECTOR_PACKAGE_NAME
static final int
SELECTOR_CHILD
static final int
SELECTOR_CONTAINER
static final int
SELECTOR_PATTERN
static final int
SELECTOR_PARENT
static final int
SELECTOR_COUNT
static final int
SELECTOR_LONG_CLICKABLE
static final int
SELECTOR_TEXT_REGEX
static final int
SELECTOR_CLASS_REGEX
static final int
SELECTOR_DESCRIPTION_REGEX
static final int
SELECTOR_PACKAGE_NAME_REGEX
static final int
SELECTOR_RESOURCE_ID
static final int
SELECTOR_CHECKABLE
static final int
SELECTOR_RESOURCE_ID_REGEX
private android.util.SparseArray
mSelectorAttributes
Constructors Summary
public UiSelector()

since
API Level 16


             
      
    
UiSelector(UiSelector selector)

        mSelectorAttributes = selector.cloneSelector().mSelectorAttributes;
    
Methods Summary
private com.android.uiautomator.core.UiSelectorbuildSelector(int selectorId, java.lang.Object selectorValue)
Building a UiSelector always returns a new UiSelector and never modifies the existing UiSelector being used.

        UiSelector selector = new UiSelector(this);
        if (selectorId == SELECTOR_CHILD || selectorId == SELECTOR_PARENT)
            selector.getLastSubSelector().mSelectorAttributes.put(selectorId, selectorValue);
        else
            selector.mSelectorAttributes.put(selectorId, selectorValue);
        return selector;
    
public com.android.uiautomator.core.UiSelectorcheckable(boolean val)
Set the search criteria to match widgets that are checkable. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

param
val Value to match
return
UiSelector with the specified search criteria
since
API Level 18

        return buildSelector(SELECTOR_CHECKABLE, val);
    
public com.android.uiautomator.core.UiSelectorchecked(boolean val)
Set the search criteria to match widgets that are currently checked (usually for checkboxes). Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

param
val Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_CHECKED, val);
    
public com.android.uiautomator.core.UiSelectorchildSelector(com.android.uiautomator.core.UiSelector selector)
Adds a child UiSelector criteria to this selector. Use this selector to narrow the search scope to child widgets under a specific parent widget.

param
selector
return
UiSelector with this added search criterion
since
API Level 16

        return buildSelector(SELECTOR_CHILD, selector);
    
public com.android.uiautomator.core.UiSelectorclassName(java.lang.String className)
Set the search criteria to match the class property for a widget (for example, "android.widget.Button").

param
className Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_CLASS, className);
    
public com.android.uiautomator.core.UiSelectorclassName(java.lang.Class type)
Set the search criteria to match the class property for a widget (for example, "android.widget.Button").

param
type type
return
UiSelector with the specified search criteria
since
API Level 17

        return buildSelector(SELECTOR_CLASS, type.getName());
    
public com.android.uiautomator.core.UiSelectorclassNameMatches(java.lang.String regex)
Set the search criteria to match the class property for a widget, using a regular expression.

param
regex a regular expression
return
UiSelector with the specified search criteria
since
API Level 17

        return buildSelector(SELECTOR_CLASS_REGEX, Pattern.compile(regex));
    
public com.android.uiautomator.core.UiSelectorclickable(boolean val)
Set the search criteria to match widgets that are clickable. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

param
val Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_CLICKABLE, val);
    
protected com.android.uiautomator.core.UiSelectorcloneSelector()

since
API Level 17

        UiSelector ret = new UiSelector();
        ret.mSelectorAttributes = mSelectorAttributes.clone();
        if (hasChildSelector())
            ret.mSelectorAttributes.put(SELECTOR_CHILD, new UiSelector(getChildSelector()));
        if (hasParentSelector())
            ret.mSelectorAttributes.put(SELECTOR_PARENT, new UiSelector(getParentSelector()));
        if (hasPatternSelector())
            ret.mSelectorAttributes.put(SELECTOR_PATTERN, new UiSelector(getPatternSelector()));
        return ret;
    
private com.android.uiautomator.core.UiSelectorcontainerSelector(com.android.uiautomator.core.UiSelector selector)

        return buildSelector(SELECTOR_CONTAINER, selector);
    
public com.android.uiautomator.core.UiSelectordescription(java.lang.String desc)
Set the search criteria to match the content-description property for a widget. The content-description is typically used by the Android Accessibility framework to provide an audio prompt for the widget when the widget is selected. The content-description for the widget must match exactly with the string in your input argument. Matching is case-sensitive.

param
desc Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_DESCRIPTION, desc);
    
public com.android.uiautomator.core.UiSelectordescriptionContains(java.lang.String desc)
Set the search criteria to match the content-description property for a widget. The content-description is typically used by the Android Accessibility framework to provide an audio prompt for the widget when the widget is selected. The content-description for the widget must contain the string in your input argument. Matching is case-insensitive.

param
desc Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_CONTAINS_DESCRIPTION, desc);
    
public com.android.uiautomator.core.UiSelectordescriptionMatches(java.lang.String regex)
Set the search criteria to match the content-description property for a widget. The content-description is typically used by the Android Accessibility framework to provide an audio prompt for the widget when the widget is selected. The content-description for the widget must match exactly with the string in your input argument.

param
regex a regular expression
return
UiSelector with the specified search criteria
since
API Level 17

        return buildSelector(SELECTOR_DESCRIPTION_REGEX, Pattern.compile(regex));
    
public com.android.uiautomator.core.UiSelectordescriptionStartsWith(java.lang.String desc)
Set the search criteria to match the content-description property for a widget. The content-description is typically used by the Android Accessibility framework to provide an audio prompt for the widget when the widget is selected. The content-description for the widget must start with the string in your input argument. Matching is case-insensitive.

param
desc Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_START_DESCRIPTION, desc);
    
java.lang.StringdumpToString(boolean all)

        StringBuilder builder = new StringBuilder();
        builder.append(UiSelector.class.getSimpleName() + "[");
        final int criterionCount = mSelectorAttributes.size();
        for (int i = 0; i < criterionCount; i++) {
            if (i > 0) {
                builder.append(", ");
            }
            final int criterion = mSelectorAttributes.keyAt(i);
            switch (criterion) {
            case SELECTOR_TEXT:
                builder.append("TEXT=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_TEXT_REGEX:
                builder.append("TEXT_REGEX=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_START_TEXT:
                builder.append("START_TEXT=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_CONTAINS_TEXT:
                builder.append("CONTAINS_TEXT=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_CLASS:
                builder.append("CLASS=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_CLASS_REGEX:
                builder.append("CLASS_REGEX=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_DESCRIPTION:
                builder.append("DESCRIPTION=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_DESCRIPTION_REGEX:
                builder.append("DESCRIPTION_REGEX=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_START_DESCRIPTION:
                builder.append("START_DESCRIPTION=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_CONTAINS_DESCRIPTION:
                builder.append("CONTAINS_DESCRIPTION=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_INDEX:
                builder.append("INDEX=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_INSTANCE:
                builder.append("INSTANCE=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_ENABLED:
                builder.append("ENABLED=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_FOCUSED:
                builder.append("FOCUSED=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_FOCUSABLE:
                builder.append("FOCUSABLE=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_SCROLLABLE:
                builder.append("SCROLLABLE=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_CLICKABLE:
                builder.append("CLICKABLE=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_CHECKABLE:
                builder.append("CHECKABLE=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_LONG_CLICKABLE:
                builder.append("LONG_CLICKABLE=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_CHECKED:
                builder.append("CHECKED=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_SELECTED:
                builder.append("SELECTED=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_ID:
                builder.append("ID=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_CHILD:
                if (all)
                    builder.append("CHILD=").append(mSelectorAttributes.valueAt(i));
                else
                    builder.append("CHILD[..]");
                break;
            case SELECTOR_PATTERN:
                if (all)
                    builder.append("PATTERN=").append(mSelectorAttributes.valueAt(i));
                else
                    builder.append("PATTERN[..]");
                break;
            case SELECTOR_CONTAINER:
                if (all)
                    builder.append("CONTAINER=").append(mSelectorAttributes.valueAt(i));
                else
                    builder.append("CONTAINER[..]");
                break;
            case SELECTOR_PARENT:
                if (all)
                    builder.append("PARENT=").append(mSelectorAttributes.valueAt(i));
                else
                    builder.append("PARENT[..]");
                break;
            case SELECTOR_COUNT:
                builder.append("COUNT=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_PACKAGE_NAME:
                builder.append("PACKAGE NAME=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_PACKAGE_NAME_REGEX:
                builder.append("PACKAGE_NAME_REGEX=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_RESOURCE_ID:
                builder.append("RESOURCE_ID=").append(mSelectorAttributes.valueAt(i));
                break;
            case SELECTOR_RESOURCE_ID_REGEX:
                builder.append("RESOURCE_ID_REGEX=").append(mSelectorAttributes.valueAt(i));
                break;
            default:
                builder.append("UNDEFINED="+criterion+" ").append(mSelectorAttributes.valueAt(i));
            }
        }
        builder.append("]");
        return builder.toString();
    
public com.android.uiautomator.core.UiSelectorenabled(boolean val)
Set the search criteria to match widgets that are enabled. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

param
val Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_ENABLED, val);
    
public com.android.uiautomator.core.UiSelectorfocusable(boolean val)
Set the search criteria to match widgets that are focusable. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

param
val Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_FOCUSABLE, val);
    
public com.android.uiautomator.core.UiSelectorfocused(boolean val)
Set the search criteria to match widgets that have focus. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

param
val Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_FOCUSED, val);
    
public com.android.uiautomator.core.UiSelectorfromParent(com.android.uiautomator.core.UiSelector selector)
Adds a child UiSelector criteria to this selector which is used to start search from the parent widget. Use this selector to narrow the search scope to sibling widgets as well all child widgets under a parent.

param
selector
return
UiSelector with this added search criterion
since
API Level 16

        return buildSelector(SELECTOR_PARENT, selector);
    
booleangetBoolean(int criterion)

        return (Boolean) mSelectorAttributes.get(criterion, false);
    
com.android.uiautomator.core.UiSelectorgetChildSelector()
Selectors may have a hierarchy defined by specifying child nodes to be matched. It is not necessary that every selector have more than one level. A selector can also be a single level referencing only one node. In such cases the return it null.

return
a child selector if one exists. Else null if this selector does not reference child node.

        UiSelector selector = (UiSelector)mSelectorAttributes.get(UiSelector.SELECTOR_CHILD, null);
        if (selector != null)
            return new UiSelector(selector);
        return null;
    
com.android.uiautomator.core.UiSelectorgetContainerSelector()

        UiSelector selector =
                (UiSelector)mSelectorAttributes.get(UiSelector.SELECTOR_CONTAINER, null);
        if (selector != null)
            return new UiSelector(selector);
        return null;
    
intgetInstance()

        return getInt(UiSelector.SELECTOR_INSTANCE);
    
intgetInt(int criterion)

        return (Integer) mSelectorAttributes.get(criterion, 0);
    
private com.android.uiautomator.core.UiSelectorgetLastSubSelector()
Returns the deepest selector in the chain of possible sub selectors. A chain of selector is created when either of {@link UiSelector#childSelector(UiSelector)} or {@link UiSelector#fromParent(UiSelector)} are used once or more in the construction of a selector.

return
last UiSelector in chain

        if (mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_CHILD) >= 0) {
            UiSelector child = (UiSelector)mSelectorAttributes.get(UiSelector.SELECTOR_CHILD);
            if (child.getLastSubSelector() == null) {
                return child;
            }
            return child.getLastSubSelector();
        } else if (mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_PARENT) >= 0) {
            UiSelector parent = (UiSelector)mSelectorAttributes.get(UiSelector.SELECTOR_PARENT);
            if (parent.getLastSubSelector() == null) {
                return parent;
            }
            return parent.getLastSubSelector();
        }
        return this;
    
com.android.uiautomator.core.UiSelectorgetParentSelector()

        UiSelector selector =
                (UiSelector) mSelectorAttributes.get(UiSelector.SELECTOR_PARENT, null);
        if (selector != null)
            return new UiSelector(selector);
        return null;
    
java.util.regex.PatterngetPattern(int criterion)

        return (Pattern) mSelectorAttributes.get(criterion, null);
    
com.android.uiautomator.core.UiSelectorgetPatternSelector()

        UiSelector selector =
                (UiSelector)mSelectorAttributes.get(UiSelector.SELECTOR_PATTERN, null);
        if (selector != null)
            return new UiSelector(selector);
        return null;
    
java.lang.StringgetString(int criterion)

        return (String) mSelectorAttributes.get(criterion, null);
    
booleanhasChildSelector()

        if (mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_CHILD) < 0) {
            return false;
        }
        return true;
    
booleanhasContainerSelector()

        if (mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_CONTAINER) < 0) {
            return false;
        }
        return true;
    
booleanhasParentSelector()

        if (mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_PARENT) < 0) {
            return false;
        }
        return true;
    
booleanhasPatternSelector()

        if (mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_PATTERN) < 0) {
            return false;
        }
        return true;
    
public com.android.uiautomator.core.UiSelectorindex(int index)
Set the search criteria to match the widget by its node index in the layout hierarchy. The index value must be 0 or greater. Using the index can be unreliable and should only be used as a last resort for matching. Instead, consider using the {@link #instance(int)} method.

param
index Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_INDEX, index);
    
public com.android.uiautomator.core.UiSelectorinstance(int instance)
Set the search criteria to match the widget by its instance number. The instance value must be 0 or greater, where the first instance is 0. For example, to simulate a user click on the third image that is enabled in a UI screen, you could specify a a search criteria where the instance is 2, the {@link #className(String)} matches the image widget class, and {@link #enabled(boolean)} is true. The code would look like this: new UiSelector().className("android.widget.ImageView") .enabled(true).instance(2);

param
instance Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_INSTANCE, instance);
    
booleanisLeaf()
Leaf selector indicates no more child or parent selectors are declared in the this selector.

return
true if is leaf.

        if (mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_CHILD) < 0 &&
                mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_PARENT) < 0) {
            return true;
        }
        return false;
    
booleanisMatchFor(android.view.accessibility.AccessibilityNodeInfo node, int index)

        int size = mSelectorAttributes.size();
        for(int x = 0; x < size; x++) {
            CharSequence s = null;
            int criterion = mSelectorAttributes.keyAt(x);
            switch(criterion) {
            case UiSelector.SELECTOR_INDEX:
                if (index != this.getInt(criterion))
                    return false;
                break;
            case UiSelector.SELECTOR_CHECKED:
                if (node.isChecked() != getBoolean(criterion)) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_CLASS:
                s = node.getClassName();
                if (s == null || !s.toString().contentEquals(getString(criterion))) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_CLASS_REGEX:
                s = node.getClassName();
                if (s == null || !getPattern(criterion).matcher(s).matches()) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_CLICKABLE:
                if (node.isClickable() != getBoolean(criterion)) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_CHECKABLE:
                if (node.isCheckable() != getBoolean(criterion)) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_LONG_CLICKABLE:
                if (node.isLongClickable() != getBoolean(criterion)) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_CONTAINS_DESCRIPTION:
                s = node.getContentDescription();
                if (s == null || !s.toString().toLowerCase()
                        .contains(getString(criterion).toLowerCase())) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_START_DESCRIPTION:
                s = node.getContentDescription();
                if (s == null || !s.toString().toLowerCase()
                        .startsWith(getString(criterion).toLowerCase())) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_DESCRIPTION:
                s = node.getContentDescription();
                if (s == null || !s.toString().contentEquals(getString(criterion))) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_DESCRIPTION_REGEX:
                s = node.getContentDescription();
                if (s == null || !getPattern(criterion).matcher(s).matches()) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_CONTAINS_TEXT:
                s = node.getText();
                if (s == null || !s.toString().toLowerCase()
                        .contains(getString(criterion).toLowerCase())) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_START_TEXT:
                s = node.getText();
                if (s == null || !s.toString().toLowerCase()
                        .startsWith(getString(criterion).toLowerCase())) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_TEXT:
                s = node.getText();
                if (s == null || !s.toString().contentEquals(getString(criterion))) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_TEXT_REGEX:
                s = node.getText();
                if (s == null || !getPattern(criterion).matcher(s).matches()) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_ENABLED:
                if (node.isEnabled() != getBoolean(criterion)) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_FOCUSABLE:
                if (node.isFocusable() != getBoolean(criterion)) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_FOCUSED:
                if (node.isFocused() != getBoolean(criterion)) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_ID:
                break; //TODO: do we need this for AccessibilityNodeInfo.id?
            case UiSelector.SELECTOR_PACKAGE_NAME:
                s = node.getPackageName();
                if (s == null || !s.toString().contentEquals(getString(criterion))) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_PACKAGE_NAME_REGEX:
                s = node.getPackageName();
                if (s == null || !getPattern(criterion).matcher(s).matches()) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_SCROLLABLE:
                if (node.isScrollable() != getBoolean(criterion)) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_SELECTED:
                if (node.isSelected() != getBoolean(criterion)) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_RESOURCE_ID:
                s = node.getViewIdResourceName();
                if (s == null || !s.toString().contentEquals(getString(criterion))) {
                    return false;
                }
                break;
            case UiSelector.SELECTOR_RESOURCE_ID_REGEX:
                s = node.getViewIdResourceName();
                if (s == null || !getPattern(criterion).matcher(s).matches()) {
                    return false;
                }
                break;
            }
        }
        return matchOrUpdateInstance();
    
public com.android.uiautomator.core.UiSelectorlongClickable(boolean val)
Set the search criteria to match widgets that are long-clickable. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

param
val Value to match
return
UiSelector with the specified search criteria
since
API Level 17

        return buildSelector(SELECTOR_LONG_CLICKABLE, val);
    
private booleanmatchOrUpdateInstance()

        int currentSelectorCounter = 0;
        int currentSelectorInstance = 0;

        // matched attributes - now check for matching instance number
        if (mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_INSTANCE) >= 0) {
            currentSelectorInstance =
                    (Integer)mSelectorAttributes.get(UiSelector.SELECTOR_INSTANCE);
        }

        // instance is required. Add count if not already counting
        if (mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_COUNT) >= 0) {
            currentSelectorCounter = (Integer)mSelectorAttributes.get(UiSelector.SELECTOR_COUNT);
        }

        // Verify
        if (currentSelectorInstance == currentSelectorCounter) {
            return true;
        }
        // Update count
        if (currentSelectorInstance > currentSelectorCounter) {
            mSelectorAttributes.put(UiSelector.SELECTOR_COUNT, ++currentSelectorCounter);
        }
        return false;
    
public com.android.uiautomator.core.UiSelectorpackageName(java.lang.String name)
Set the search criteria to match the package name of the application that contains the widget.

param
name Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_PACKAGE_NAME, name);
    
public com.android.uiautomator.core.UiSelectorpackageNameMatches(java.lang.String regex)
Set the search criteria to match the package name of the application that contains the widget.

param
regex a regular expression
return
UiSelector with the specified search criteria
since
API Level 17

        return buildSelector(SELECTOR_PACKAGE_NAME_REGEX, Pattern.compile(regex));
    
static com.android.uiautomator.core.UiSelectorpatternBuilder(com.android.uiautomator.core.UiSelector selector)

        if (!selector.hasPatternSelector()) {
            return new UiSelector().patternSelector(selector);
        }
        return selector;
    
static com.android.uiautomator.core.UiSelectorpatternBuilder(com.android.uiautomator.core.UiSelector container, com.android.uiautomator.core.UiSelector pattern)

        return new UiSelector(
                new UiSelector().containerSelector(container).patternSelector(pattern));
    
private com.android.uiautomator.core.UiSelectorpatternSelector(com.android.uiautomator.core.UiSelector selector)

        return buildSelector(SELECTOR_PATTERN, selector);
    
public com.android.uiautomator.core.UiSelectorresourceId(java.lang.String id)
Set the search criteria to match the given resource ID.

param
id Value to match
return
UiSelector with the specified search criteria
since
API Level 18

        return buildSelector(SELECTOR_RESOURCE_ID, id);
    
public com.android.uiautomator.core.UiSelectorresourceIdMatches(java.lang.String regex)
Set the search criteria to match the resource ID of the widget, using a regular expression.

param
regex a regular expression
return
UiSelector with the specified search criteria
since
API Level 18

        return buildSelector(SELECTOR_RESOURCE_ID_REGEX, Pattern.compile(regex));
    
public com.android.uiautomator.core.UiSelectorscrollable(boolean val)
Set the search criteria to match widgets that are scrollable. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

param
val Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_SCROLLABLE, val);
    
public com.android.uiautomator.core.UiSelectorselected(boolean val)
Set the search criteria to match widgets that are currently selected. Typically, using this search criteria alone is not useful. You should also include additional criteria, such as text, content-description, or the class name for a widget. If no other search criteria is specified, and there is more than one matching widget, the first widget in the tree is selected.

param
val Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_SELECTED, val);
    
public com.android.uiautomator.core.UiSelectortext(java.lang.String text)
Set the search criteria to match the visible text displayed in a widget (for example, the text label to launch an app). The text for the element must match exactly with the string in your input argument. Matching is case-sensitive.

param
text Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_TEXT, text);
    
public com.android.uiautomator.core.UiSelectortextContains(java.lang.String text)
Set the search criteria to match the visible text in a widget where the visible text must contain the string in your input argument. The matching is case-sensitive.

param
text Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_CONTAINS_TEXT, text);
    
public com.android.uiautomator.core.UiSelectortextMatches(java.lang.String regex)
Set the search criteria to match the visible text displayed in a layout element, using a regular expression. The text in the widget must match exactly with the string in your input argument.

param
regex a regular expression
return
UiSelector with the specified search criteria
since
API Level 17

        return buildSelector(SELECTOR_TEXT_REGEX, Pattern.compile(regex));
    
public com.android.uiautomator.core.UiSelectortextStartsWith(java.lang.String text)
Set the search criteria to match visible text in a widget that is prefixed by the text parameter. The matching is case-insensitive.

param
text Value to match
return
UiSelector with the specified search criteria
since
API Level 16

        return buildSelector(SELECTOR_START_TEXT, text);
    
public java.lang.StringtoString()

        return dumpToString(true);