public class By


By is a utility class which enables the creation of BySelectors in a concise manner.

Its primary function is to provide static factory methods for constructing BySelectors using a shortened syntax. For example, you would use findObject(By.text("foo")) rather than findObject(new BySelector().text("foo")) to select UI elements with the text value "foo".

Summary

Public methods

static @NonNull BySelector
checkable(boolean isCheckable)

Constructs a new BySelector and sets the checkable criteria.

static @NonNull BySelector
checked(boolean isChecked)

Constructs a new BySelector and sets the checked criteria.

static @NonNull BySelector
clazz(@NonNull Pattern className)

Constructs a new BySelector and sets the class name criteria.

static @NonNull BySelector
clazz(@NonNull String className)

Constructs a new BySelector and sets the class name criteria.

static @NonNull BySelector

Constructs a new BySelector and sets the class name criteria.

static @NonNull BySelector
clazz(@NonNull String packageName, @NonNull String className)

Constructs a new BySelector and sets the class name criteria.

static @NonNull BySelector
clickable(boolean isClickable)

Constructs a new BySelector and sets the clickable criteria.

static @NonNull BySelector
copy(@NonNull BySelector original)

Constructs a new BySelector and copies the criteria from original.

static @NonNull BySelector
depth(int depth)

Constructs a new BySelector and sets the depth criteria.

static @NonNull BySelector
desc(@NonNull Pattern contentDescription)

Constructs a new BySelector and sets the content description criteria.

static @NonNull BySelector
desc(@NonNull String contentDescription)

Constructs a new BySelector and sets the content description criteria.

static @NonNull BySelector

Constructs a new BySelector and sets the content description criteria.

static @NonNull BySelector

Constructs a new BySelector and sets the content description criteria.

static @NonNull BySelector

Constructs a new BySelector and sets the content description criteria.

static @NonNull BySelector
@RequiresApi(value = 30)
displayId(int displayId)

Constructs a new BySelector and sets the display ID criteria.

static @NonNull BySelector
enabled(boolean isEnabled)

Constructs a new BySelector and sets the enabled criteria.

static @NonNull BySelector
focusable(boolean isFocusable)

Constructs a new BySelector and sets the focusable criteria.

static @NonNull BySelector
focused(boolean isFocused)

Constructs a new BySelector and sets the focused criteria.

static @NonNull BySelector
hasAncestor(@NonNull BySelector ancestorSelector)

Constructs a new BySelector and adds an ancestor selector criteria.

static @NonNull BySelector
hasAncestor(
    @NonNull BySelector ancestorSelector,
    @IntRange(from = 1) int maxAncestorDistance
)

Constructs a new BySelector and adds an ancestor selector criteria.

static @NonNull BySelector
hasChild(@NonNull BySelector childSelector)

Constructs a new BySelector and adds a child selector criteria.

static @NonNull BySelector
hasDescendant(@NonNull BySelector descendantSelector)

Constructs a new BySelector and adds a descendant selector criteria.

static @NonNull BySelector
hasDescendant(@NonNull BySelector descendantSelector, int maxDepth)

Constructs a new BySelector and adds a descendant selector criteria.

static @NonNull BySelector
hasParent(@NonNull BySelector parentSelector)

Constructs a new BySelector and adds a parent selector criteria.

static @NonNull BySelector
@RequiresApi(value = 26)
hint(@NonNull String hint)

Constructs a new BySelector and sets the hint value criteria.

static @NonNull BySelector
@RequiresApi(value = 26)
hint(@NonNull Pattern regex)

Constructs a new BySelector and sets the hint value criteria.

static @NonNull BySelector
@RequiresApi(value = 26)
hintContains(@NonNull String substring)

Constructs a new BySelector and sets the hint value criteria.

static @NonNull BySelector
@RequiresApi(value = 26)
hintEndsWith(@NonNull String suffix)

Constructs a new BySelector and sets the hint value criteria.

static @NonNull BySelector
@RequiresApi(value = 26)
hintStartsWith(@NonNull String prefix)

Constructs a new BySelector and sets the hint value criteria.

static @NonNull BySelector
longClickable(boolean isLongClickable)

Constructs a new BySelector and sets the long clickable criteria.

static @NonNull BySelector
pkg(@NonNull Pattern applicationPackage)

Constructs a new BySelector and sets the application package name criteria.

static @NonNull BySelector
pkg(@NonNull String applicationPackage)

Constructs a new BySelector and sets the application package name criteria.

static @NonNull BySelector
res(@NonNull Pattern resourceName)

Constructs a new BySelector and sets the resource id criteria.

static @NonNull BySelector
res(@NonNull String resourceName)

Constructs a new BySelector and sets the resource name criteria.

static @NonNull BySelector
res(@NonNull String resourcePackage, @NonNull String resourceId)

Constructs a new BySelector and sets the resource name criteria.

static @NonNull BySelector
scrollable(boolean isScrollable)

Constructs a new BySelector and sets the scrollable criteria.

static @NonNull BySelector
selected(boolean isSelected)

Constructs a new BySelector and sets the selected criteria.

static @NonNull BySelector

Constructs a new BySelector and sets the text value criteria.

static @NonNull BySelector

Constructs a new BySelector and sets the text value criteria.

static @NonNull BySelector

Constructs a new BySelector and sets the text value criteria.

static @NonNull BySelector

Constructs a new BySelector and sets the text value criteria.

static @NonNull BySelector

Constructs a new BySelector and sets the text value criteria.

Public methods

checkable

Added in 2.2.0
public static @NonNull BySelector checkable(boolean isCheckable)

Constructs a new BySelector and sets the checkable criteria.

See also
checkable

BySelector.checkable(boolean)

checked

Added in 2.2.0
public static @NonNull BySelector checked(boolean isChecked)

Constructs a new BySelector and sets the checked criteria.

See also
checked

BySelector.checked(boolean)

clazz

Added in 2.2.0
public static @NonNull BySelector clazz(@NonNull Pattern className)

Constructs a new BySelector and sets the class name criteria.

See also
clazz

BySelector.clazz(Pattern)

clazz

Added in 2.2.0
public static @NonNull BySelector clazz(@NonNull String className)

Constructs a new BySelector and sets the class name criteria.

See also
clazz

BySelector.clazz(String)

clazz

Added in 2.2.0
public static @NonNull BySelector clazz(@NonNull Class clazz)

Constructs a new BySelector and sets the class name criteria.

See also
clazz

BySelector.clazz(Class)

clazz

Added in 2.2.0
public static @NonNull BySelector clazz(@NonNull String packageName, @NonNull String className)

Constructs a new BySelector and sets the class name criteria.

See also
clazz

BySelector.clazz(String, String)

clickable

Added in 2.2.0
public static @NonNull BySelector clickable(boolean isClickable)

Constructs a new BySelector and sets the clickable criteria.

See also
clickable

BySelector.clickable(boolean)

copy

Added in 2.2.0
public static @NonNull BySelector copy(@NonNull BySelector original)

Constructs a new BySelector and copies the criteria from original.

depth

Added in 2.2.0
public static @NonNull BySelector depth(int depth)

Constructs a new BySelector and sets the depth criteria.

desc

Added in 2.2.0
public static @NonNull BySelector desc(@NonNull Pattern contentDescription)

Constructs a new BySelector and sets the content description criteria.

See also
desc

BySelector.desc(Pattern)

desc

Added in 2.2.0
public static @NonNull BySelector desc(@NonNull String contentDescription)

Constructs a new BySelector and sets the content description criteria.

See also
desc

BySelector.desc(String)

descContains

Added in 2.2.0
public static @NonNull BySelector descContains(@NonNull String substring)

Constructs a new BySelector and sets the content description criteria.

See also
descContains

BySelector.descContains(String)

descEndsWith

Added in 2.2.0
public static @NonNull BySelector descEndsWith(@NonNull String suffix)

Constructs a new BySelector and sets the content description criteria.

See also
descEndsWith

BySelector.descEndsWith(String)

descStartsWith

Added in 2.2.0
public static @NonNull BySelector descStartsWith(@NonNull String prefix)

Constructs a new BySelector and sets the content description criteria.

See also
descStartsWith

BySelector.descStartsWith(String)

displayId

Added in 2.3.0
@RequiresApi(value = 30)
public static @NonNull BySelector displayId(int displayId)

Constructs a new BySelector and sets the display ID criteria.

See also
displayId

BySelector.displayId(int)

enabled

Added in 2.2.0
public static @NonNull BySelector enabled(boolean isEnabled)

Constructs a new BySelector and sets the enabled criteria.

See also
enabled

BySelector.enabled(boolean)

focusable

Added in 2.2.0
public static @NonNull BySelector focusable(boolean isFocusable)

Constructs a new BySelector and sets the focusable criteria.

See also
focusable

BySelector.focusable(boolean)

focused

Added in 2.2.0
public static @NonNull BySelector focused(boolean isFocused)

Constructs a new BySelector and sets the focused criteria.

See also
focused

BySelector.focused(boolean)

hasAncestor

Added in 2.3.0
public static @NonNull BySelector hasAncestor(@NonNull BySelector ancestorSelector)

Constructs a new BySelector and adds an ancestor selector criteria.

See also
hasAncestor

BySelector.hasAncestor(BySelector)

hasAncestor

Added in 2.3.0
public static @NonNull BySelector hasAncestor(
    @NonNull BySelector ancestorSelector,
    @IntRange(from = 1) int maxAncestorDistance
)

Constructs a new BySelector and adds an ancestor selector criteria.

See also
hasAncestor

BySelector.hasAncestor(BySelector, int)

hasChild

Added in 2.2.0
public static @NonNull BySelector hasChild(@NonNull BySelector childSelector)

Constructs a new BySelector and adds a child selector criteria.

See also
hasChild

BySelector.hasChild(BySelector)

hasDescendant

Added in 2.2.0
public static @NonNull BySelector hasDescendant(@NonNull BySelector descendantSelector)

Constructs a new BySelector and adds a descendant selector criteria.

See also
hasDescendant

BySelector.hasDescendant(BySelector)

hasDescendant

Added in 2.2.0
public static @NonNull BySelector hasDescendant(@NonNull BySelector descendantSelector, int maxDepth)

Constructs a new BySelector and adds a descendant selector criteria.

See also
hasDescendant

BySelector.hasDescendant(BySelector, int)

hasParent

Added in 2.3.0
public static @NonNull BySelector hasParent(@NonNull BySelector parentSelector)

Constructs a new BySelector and adds a parent selector criteria.

See also
hasParent

BySelector.hasParent(BySelector)

hint

Added in 2.3.0
@RequiresApi(value = 26)
public static @NonNull BySelector hint(@NonNull String hint)

Constructs a new BySelector and sets the hint value criteria.

See also
hint

BySelector.hint(String)

hint

Added in 2.3.0
@RequiresApi(value = 26)
public static @NonNull BySelector hint(@NonNull Pattern regex)

Constructs a new BySelector and sets the hint value criteria.

See also
hint

BySelector.hint(Pattern)

hintContains

Added in 2.3.0
@RequiresApi(value = 26)
public static @NonNull BySelector hintContains(@NonNull String substring)

Constructs a new BySelector and sets the hint value criteria.

See also
hintContains

BySelector.hintContains(String)

hintEndsWith

Added in 2.3.0
@RequiresApi(value = 26)
public static @NonNull BySelector hintEndsWith(@NonNull String suffix)

Constructs a new BySelector and sets the hint value criteria.

See also
hintEndsWith

BySelector.hintEndsWith(String)

hintStartsWith

Added in 2.3.0
@RequiresApi(value = 26)
public static @NonNull BySelector hintStartsWith(@NonNull String prefix)

Constructs a new BySelector and sets the hint value criteria.

See also
hintStartsWith

BySelector.hintStartsWith(String)

longClickable

Added in 2.2.0
public static @NonNull BySelector longClickable(boolean isLongClickable)

Constructs a new BySelector and sets the long clickable criteria.

See also
longClickable

BySelector.longClickable(boolean)

pkg

Added in 2.2.0
public static @NonNull BySelector pkg(@NonNull Pattern applicationPackage)

Constructs a new BySelector and sets the application package name criteria.

See also
pkg

BySelector.pkg(Pattern)

pkg

Added in 2.2.0
public static @NonNull BySelector pkg(@NonNull String applicationPackage)

Constructs a new BySelector and sets the application package name criteria.

See also
pkg

BySelector.pkg(String)

res

Added in 2.2.0
public static @NonNull BySelector res(@NonNull Pattern resourceName)

Constructs a new BySelector and sets the resource id criteria.

See also
res

BySelector.res(Pattern)

res

Added in 2.2.0
public static @NonNull BySelector res(@NonNull String resourceName)

Constructs a new BySelector and sets the resource name criteria.

See also
res

BySelector.res(String)

res

Added in 2.2.0
public static @NonNull BySelector res(@NonNull String resourcePackage, @NonNull String resourceId)

Constructs a new BySelector and sets the resource name criteria.

See also
res

BySelector.res(String, String)

scrollable

Added in 2.2.0
public static @NonNull BySelector scrollable(boolean isScrollable)

Constructs a new BySelector and sets the scrollable criteria.

See also
scrollable

BySelector.scrollable(boolean)

selected

Added in 2.2.0
public static @NonNull BySelector selected(boolean isSelected)

Constructs a new BySelector and sets the selected criteria.

See also
selected

BySelector.selected(boolean)

text

Added in 2.2.0
public static @NonNull BySelector text(@NonNull Pattern regex)

Constructs a new BySelector and sets the text value criteria.

See also
text

BySelector.text(Pattern)

text

Added in 2.2.0
public static @NonNull BySelector text(@NonNull String text)

Constructs a new BySelector and sets the text value criteria.

See also
text

BySelector.text(String)

textContains

Added in 2.2.0
public static @NonNull BySelector textContains(@NonNull String substring)

Constructs a new BySelector and sets the text value criteria.

See also
textContains

BySelector.textContains(String)

textEndsWith

Added in 2.2.0
public static @NonNull BySelector textEndsWith(@NonNull String suffix)

Constructs a new BySelector and sets the text value criteria.

See also
textEndsWith

BySelector.textEndsWith(String)

textStartsWith

Added in 2.2.0
public static @NonNull BySelector textStartsWith(@NonNull String prefix)

Constructs a new BySelector and sets the text value criteria.

See also
textStartsWith

BySelector.textStartsWith(String)