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 @