public class

By

extends java.lang.Object

 java.lang.Object

↳androidx.test.uiautomator.By

Gradle dependencies

compile group: 'androidx.test.uiautomator', name: 'uiautomator', version: '2.4.0-alpha01'

  • groupId: androidx.test.uiautomator
  • artifactId: uiautomator
  • version: 2.4.0-alpha01

Artifact androidx.test.uiautomator:uiautomator:2.4.0-alpha01 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test.uiautomator:uiautomator com.android.support.test.uiautomator:uiautomator

Androidx class mapping:

androidx.test.uiautomator.By android.support.test.uiautomator.By

Overview

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

Methods
public static BySelectorcheckable(boolean isCheckable)

Constructs a new BySelector and sets the checkable criteria.

public static BySelectorchecked(boolean isChecked)

Constructs a new BySelector and sets the checked criteria.

public static BySelectorclazz(java.lang.Class clazz)

Constructs a new BySelector and sets the class name criteria.

public static BySelectorclazz(java.util.regex.Pattern className)

Constructs a new BySelector and sets the class name criteria.

public static BySelectorclazz(java.lang.String className)

Constructs a new BySelector and sets the class name criteria.

public static BySelectorclazz(java.lang.String packageName, java.lang.String className)

Constructs a new BySelector and sets the class name criteria.

public static BySelectorclickable(boolean isClickable)

Constructs a new BySelector and sets the clickable criteria.

public static BySelectorcopy(BySelector original)

Constructs a new BySelector and copies the criteria from original.

public static BySelectordepth(int depth)

Constructs a new BySelector and sets the depth criteria.

public static BySelectordesc(java.util.regex.Pattern contentDescription)

Constructs a new BySelector and sets the content description criteria.

public static BySelectordesc(java.lang.String contentDescription)

Constructs a new BySelector and sets the content description criteria.

public static BySelectordescContains(java.lang.String substring)

Constructs a new BySelector and sets the content description criteria.

public static BySelectordescEndsWith(java.lang.String suffix)

Constructs a new BySelector and sets the content description criteria.

public static BySelectordescStartsWith(java.lang.String prefix)

Constructs a new BySelector and sets the content description criteria.

public static BySelectordisplayId(int displayId)

Constructs a new BySelector and sets the display ID criteria.

public static BySelectorenabled(boolean isEnabled)

Constructs a new BySelector and sets the enabled criteria.

public static BySelectorfocusable(boolean isFocusable)

Constructs a new BySelector and sets the focusable criteria.

public static BySelectorfocused(boolean isFocused)

Constructs a new BySelector and sets the focused criteria.

public static BySelectorhasAncestor(BySelector ancestorSelector)

Constructs a new BySelector and adds an ancestor selector criteria.

public static BySelectorhasAncestor(BySelector ancestorSelector, int maxAncestorDistance)

Constructs a new BySelector and adds an ancestor selector criteria.

public static BySelectorhasChild(BySelector childSelector)

Constructs a new BySelector and adds a child selector criteria.

public static BySelectorhasDescendant(BySelector descendantSelector)

Constructs a new BySelector and adds a descendant selector criteria.

public static BySelectorhasDescendant(BySelector descendantSelector, int maxDepth)

Constructs a new BySelector and adds a descendant selector criteria.

public static BySelectorhasParent(BySelector parentSelector)

Constructs a new BySelector and adds a parent selector criteria.

public static BySelectorhint(java.util.regex.Pattern regex)

Constructs a new BySelector and sets the hint value criteria.

public static BySelectorhint(java.lang.String hint)

Constructs a new BySelector and sets the hint value criteria.

public static BySelectorhintContains(java.lang.String substring)

Constructs a new BySelector and sets the hint value criteria.

public static BySelectorhintEndsWith(java.lang.String suffix)

Constructs a new BySelector and sets the hint value criteria.

public static BySelectorhintStartsWith(java.lang.String prefix)

Constructs a new BySelector and sets the hint value criteria.

public static BySelectorlongClickable(boolean isLongClickable)

Constructs a new BySelector and sets the long clickable criteria.

public static BySelectorpkg(java.util.regex.Pattern applicationPackage)

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

public static BySelectorpkg(java.lang.String applicationPackage)

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

public static BySelectorres(java.util.regex.Pattern resourceName)

Constructs a new BySelector and sets the resource id criteria.

public static BySelectorres(java.lang.String resourceName)

Constructs a new BySelector and sets the resource name criteria.

public static BySelectorres(java.lang.String resourcePackage, java.lang.String resourceId)

Constructs a new BySelector and sets the resource name criteria.

public static BySelectorscrollable(boolean isScrollable)

Constructs a new BySelector and sets the scrollable criteria.

public static BySelectorselected(boolean isSelected)

Constructs a new BySelector and sets the selected criteria.

public static BySelectortext(java.util.regex.Pattern regex)

Constructs a new BySelector and sets the text value criteria.

public static BySelectortext(java.lang.String text)

Constructs a new BySelector and sets the text value criteria.

public static BySelectortextContains(java.lang.String substring)

Constructs a new BySelector and sets the text value criteria.

public static BySelectortextEndsWith(java.lang.String suffix)

Constructs a new BySelector and sets the text value criteria.

public static BySelectortextStartsWith(java.lang.String prefix)

Constructs a new BySelector and sets the text value criteria.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static BySelector copy(BySelector original)

Constructs a new BySelector and copies the criteria from original.

public static BySelector clazz(java.lang.String className)

Constructs a new BySelector and sets the class name criteria.

See also: BySelector.clazz(String)

public static BySelector clazz(java.lang.String packageName, java.lang.String className)

Constructs a new BySelector and sets the class name criteria.

See also: BySelector.clazz(String, String)

public static BySelector clazz(java.lang.Class clazz)

Constructs a new BySelector and sets the class name criteria.

See also: BySelector.clazz(Class)

public static BySelector clazz(java.util.regex.Pattern className)

Constructs a new BySelector and sets the class name criteria.

See also: BySelector.clazz(Pattern)

public static BySelector desc(java.lang.String contentDescription)

Constructs a new BySelector and sets the content description criteria.

See also: BySelector.desc(String)

public static BySelector descContains(java.lang.String substring)

Constructs a new BySelector and sets the content description criteria.

See also: BySelector.descContains(String)

public static BySelector descStartsWith(java.lang.String prefix)

Constructs a new BySelector and sets the content description criteria.

See also: BySelector.descStartsWith(String)

public static BySelector descEndsWith(java.lang.String suffix)

Constructs a new BySelector and sets the content description criteria.

See also: BySelector.descEndsWith(String)

public static BySelector desc(java.util.regex.Pattern contentDescription)

Constructs a new BySelector and sets the content description criteria.

See also: BySelector.desc(Pattern)

public static BySelector pkg(java.lang.String applicationPackage)

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

See also: BySelector.pkg(String)

public static BySelector pkg(java.util.regex.Pattern applicationPackage)

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

See also: BySelector.pkg(Pattern)

public static BySelector res(java.lang.String resourceName)

Constructs a new BySelector and sets the resource name criteria.

See also: BySelector.res(String)

public static BySelector res(java.lang.String resourcePackage, java.lang.String resourceId)

Constructs a new BySelector and sets the resource name criteria.

See also: BySelector.res(String, String)

public static BySelector res(java.util.regex.Pattern resourceName)

Constructs a new BySelector and sets the resource id criteria.

See also: BySelector.res(Pattern)

public static BySelector text(java.lang.String text)

Constructs a new BySelector and sets the text value criteria.

See also: BySelector.text(String)

public static BySelector textContains(java.lang.String substring)

Constructs a new BySelector and sets the text value criteria.

See also: BySelector.textContains(String)

public static BySelector textStartsWith(java.lang.String prefix)

Constructs a new BySelector and sets the text value criteria.

See also: BySelector.textStartsWith(String)

public static BySelector textEndsWith(java.lang.String suffix)

Constructs a new BySelector and sets the text value criteria.

See also: BySelector.textEndsWith(String)

public static BySelector text(java.util.regex.Pattern regex)

Constructs a new BySelector and sets the text value criteria.

See also: BySelector.text(Pattern)

public static BySelector hint(java.lang.String hint)

Constructs a new BySelector and sets the hint value criteria.

See also: BySelector.hint(String)

public static BySelector hintContains(java.lang.String substring)

Constructs a new BySelector and sets the hint value criteria.

See also: BySelector.hintContains(String)

public static BySelector hintStartsWith(java.lang.String prefix)

Constructs a new BySelector and sets the hint value criteria.

See also: BySelector.hintStartsWith(String)

public static BySelector hintEndsWith(java.lang.String suffix)

Constructs a new BySelector and sets the hint value criteria.

See also: BySelector.hintEndsWith(String)

public static BySelector hint(java.util.regex.Pattern regex)

Constructs a new BySelector and sets the hint value criteria.

See also: BySelector.hint(Pattern)

public static BySelector checkable(boolean isCheckable)

Constructs a new BySelector and sets the checkable criteria.

See also: BySelector.checkable(boolean)

public static BySelector checked(boolean isChecked)

Constructs a new BySelector and sets the checked criteria.

See also: BySelector.checked(boolean)

public static BySelector clickable(boolean isClickable)

Constructs a new BySelector and sets the clickable criteria.

See also: BySelector.clickable(boolean)

public static BySelector enabled(boolean isEnabled)

Constructs a new BySelector and sets the enabled criteria.

See also: BySelector.enabled(boolean)

public static BySelector focusable(boolean isFocusable)

Constructs a new BySelector and sets the focusable criteria.

See also: BySelector.focusable(boolean)

public static BySelector focused(boolean isFocused)

Constructs a new BySelector and sets the focused criteria.

See also: BySelector.focused(boolean)

public static BySelector longClickable(boolean isLongClickable)

Constructs a new BySelector and sets the long clickable criteria.

See also: BySelector.longClickable(boolean)

public static BySelector scrollable(boolean isScrollable)

Constructs a new BySelector and sets the scrollable criteria.

See also: BySelector.scrollable(boolean)

public static BySelector selected(boolean isSelected)

Constructs a new BySelector and sets the selected criteria.

See also: BySelector.selected(boolean)

public static BySelector depth(int depth)

Constructs a new BySelector and sets the depth criteria.

public static BySelector displayId(int displayId)

Constructs a new BySelector and sets the display ID criteria.

See also: BySelector.displayId(int)

public static BySelector hasParent(BySelector parentSelector)

Constructs a new BySelector and adds a parent selector criteria.

See also: BySelector.hasParent(BySelector)

public static BySelector hasAncestor(BySelector ancestorSelector)

Constructs a new BySelector and adds an ancestor selector criteria.

See also: BySelector.hasAncestor(BySelector)

public static BySelector hasAncestor(BySelector ancestorSelector, int maxAncestorDistance)

Constructs a new BySelector and adds an ancestor selector criteria.

See also: BySelector.hasAncestor(BySelector, int)

public static BySelector hasChild(BySelector childSelector)

Constructs a new BySelector and adds a child selector criteria.

See also: BySelector.hasChild(BySelector)

public static BySelector hasDescendant(BySelector descendantSelector)

Constructs a new BySelector and adds a descendant selector criteria.

See also: BySelector.hasDescendant(BySelector)

public static BySelector hasDescendant(BySelector descendantSelector, int maxDepth)

Constructs a new BySelector and adds a descendant selector criteria.

See also: BySelector.hasDescendant(BySelector, int)

Source

/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.test.uiautomator;

import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import java.util.regex.Pattern;

/**
 * <p>{@link By} is a utility class which enables the creation of {@link BySelector}s in a concise
 * manner.</p>
 *
 * <p>Its primary function is to provide static factory methods for constructing {@link BySelector}s
 * using a shortened syntax. For example, you would use {@code findObject(By.text("foo"))} rather
 * than {@code findObject(new BySelector().text("foo"))} to select UI elements with the text value
 * "foo".</p>
 */
public class By {

    /** This class is not meant to be instanciated */
    private By() { }


    /**
     * Constructs a new {@link BySelector} and copies the criteria from {@code original}.
     */
    public static @NonNull BySelector copy(@NonNull BySelector original) {
        return new BySelector(original);
    }

    /**
     * Constructs a new {@link BySelector} and sets the class name criteria.
     *
     * @see BySelector#clazz(String) BySelector.clazz(String)
     */
    public static @NonNull BySelector clazz(@NonNull String className) {
        return new BySelector().clazz(className);
    }

    /**
     * Constructs a new {@link BySelector} and sets the class name criteria.
     *
     * @see BySelector#clazz(String, String) BySelector.clazz(String, String)
     */
    public static @NonNull BySelector clazz(@NonNull String packageName,
            @NonNull String className) {
        return new BySelector().clazz(packageName, className);
    }

    /**
     * Constructs a new {@link BySelector} and sets the class name criteria.
     *
     * @see BySelector#clazz(Class) BySelector.clazz(Class)
     */
    public static @NonNull BySelector clazz(@NonNull Class clazz) {
        return new BySelector().clazz(clazz);
    }

    /**
     * Constructs a new {@link BySelector} and sets the class name criteria.
     *
     * @see BySelector#clazz(Pattern) BySelector.clazz(Pattern)
     */
    public static @NonNull BySelector clazz(@NonNull Pattern className) {
        return new BySelector().clazz(className);
    }

    /**
     * Constructs a new {@link BySelector} and sets the content description criteria.
     *
     * @see BySelector#desc(String) BySelector.desc(String)
     */
    public static @NonNull BySelector desc(@NonNull String contentDescription) {
        return new BySelector().desc(contentDescription);
    }

    /**
     * Constructs a new {@link BySelector} and sets the content description criteria.
     *
     * @see BySelector#descContains(String) BySelector.descContains(String)
     */
    public static @NonNull BySelector descContains(@NonNull String substring) {
        return new BySelector().descContains(substring);
    }

    /**
     * Constructs a new {@link BySelector} and sets the content description criteria.
     *
     * @see BySelector#descStartsWith(String) BySelector.descStartsWith(String)
     */
    public static @NonNull BySelector descStartsWith(@NonNull String prefix) {
        return new BySelector().descStartsWith(prefix);
    }

    /**
     * Constructs a new {@link BySelector} and sets the content description criteria.
     *
     * @see BySelector#descEndsWith(String) BySelector.descEndsWith(String)
     */
    public static @NonNull BySelector descEndsWith(@NonNull String suffix) {
        return new BySelector().descEndsWith(suffix);
    }

    /**
     * Constructs a new {@link BySelector} and sets the content description criteria.
     *
     * @see BySelector#desc(Pattern) BySelector.desc(Pattern)
     */
    public static @NonNull BySelector desc(@NonNull Pattern contentDescription) {
        return new BySelector().desc(contentDescription);
    }

    /**
     * Constructs a new {@link BySelector} and sets the application package name criteria.
     *
     * @see BySelector#pkg(String) BySelector.pkg(String)
     */
    public static @NonNull BySelector pkg(@NonNull String applicationPackage) {
        return new BySelector().pkg(applicationPackage);
    }

    /**
     * Constructs a new {@link BySelector} and sets the application package name criteria.
     *
     * @see BySelector#pkg(Pattern) BySelector.pkg(Pattern)
     */
    public static @NonNull BySelector pkg(@NonNull Pattern applicationPackage) {
        return new BySelector().pkg(applicationPackage);
    }

    /**
     * Constructs a new {@link BySelector} and sets the resource name criteria.
     *
     * @see BySelector#res(String) BySelector.res(String)
     */
    public static @NonNull BySelector res(@NonNull String resourceName) {
        return new BySelector().res(resourceName);
    }

    /**
     * Constructs a new {@link BySelector} and sets the resource name criteria.
     *
     * @see BySelector#res(String, String) BySelector.res(String, String)
     */
    public static @NonNull BySelector res(@NonNull String resourcePackage,
            @NonNull String resourceId) {
        return new BySelector().res(resourcePackage, resourceId);
    }

    /**
     * Constructs a new {@link BySelector} and sets the resource id criteria.
     *
     * @see BySelector#res(Pattern) BySelector.res(Pattern)
     */
    public static @NonNull BySelector res(@NonNull Pattern resourceName) {
        return new BySelector().res(resourceName);
    }

    /**
     * Constructs a new {@link BySelector} and sets the text value criteria.
     *
     * @see BySelector#text(String) BySelector.text(String)
     */
    public static @NonNull BySelector text(@NonNull String text) {
        return new BySelector().text(text);
    }

    /**
     * Constructs a new {@link BySelector} and sets the text value criteria.
     *
     * @see BySelector#textContains(String) BySelector.textContains(String)
     */
    public static @NonNull BySelector textContains(@NonNull String substring) {
        return new BySelector().textContains(substring);
    }

    /**
     * Constructs a new {@link BySelector} and sets the text value criteria.
     *
     * @see BySelector#textStartsWith(String) BySelector.textStartsWith(String)
     */
    public static @NonNull BySelector textStartsWith(@NonNull String prefix) {
        return new BySelector().textStartsWith(prefix);
    }

    /**
     * Constructs a new {@link BySelector} and sets the text value criteria.
     *
     * @see BySelector#textEndsWith(String) BySelector.textEndsWith(String)
     */
    public static @NonNull BySelector textEndsWith(@NonNull String suffix) {
        return new BySelector().textEndsWith(suffix);
    }

    /**
     * Constructs a new {@link BySelector} and sets the text value criteria.
     *
     * @see BySelector#text(Pattern) BySelector.text(Pattern)
     */
    public static @NonNull BySelector text(@NonNull Pattern regex) {
        return new BySelector().text(regex);
    }

    /**
     * Constructs a new {@link BySelector} and sets the hint value criteria.
     *
     * @see BySelector#hint(String) BySelector.hint(String)
     */
    @RequiresApi(26)
    public static @NonNull BySelector hint(@NonNull String hint) {
        return new BySelector().hint(hint);
    }

    /**
     * Constructs a new {@link BySelector} and sets the hint value criteria.
     *
     * @see BySelector#hintContains(String) BySelector.hintContains(String)
     */
    @RequiresApi(26)
    public static @NonNull BySelector hintContains(@NonNull String substring) {
        return new BySelector().hintContains(substring);
    }

    /**
     * Constructs a new {@link BySelector} and sets the hint value criteria.
     *
     * @see BySelector#hintStartsWith(String) BySelector.hintStartsWith(String)
     */
    @RequiresApi(26)
    public static @NonNull BySelector hintStartsWith(@NonNull String prefix) {
        return new BySelector().hintStartsWith(prefix);
    }

    /**
     * Constructs a new {@link BySelector} and sets the hint value criteria.
     *
     * @see BySelector#hintEndsWith(String) BySelector.hintEndsWith(String)
     */
    @RequiresApi(26)
    public static @NonNull BySelector hintEndsWith(@NonNull String suffix) {
        return new BySelector().hintEndsWith(suffix);
    }

    /**
     * Constructs a new {@link BySelector} and sets the hint value criteria.
     *
     * @see BySelector#hint(Pattern) BySelector.hint(Pattern)
     */
    @RequiresApi(26)
    public static @NonNull BySelector hint(@NonNull Pattern regex) {
        return new BySelector().hint(regex);
    }

    /**
     * Constructs a new {@link BySelector} and sets the checkable criteria.
     *
     * @see BySelector#checkable(boolean) BySelector.checkable(boolean)
     */
    public static @NonNull BySelector checkable(boolean isCheckable) {
        return new BySelector().checkable(isCheckable);
    }

    /**
     * Constructs a new {@link BySelector} and sets the checked criteria.
     *
     * @see BySelector#checked(boolean) BySelector.checked(boolean)
     */
    public static @NonNull BySelector checked(boolean isChecked) {
        return new BySelector().checked(isChecked);
    }

    /**
     * Constructs a new {@link BySelector} and sets the clickable criteria.
     *
     * @see BySelector#clickable(boolean) BySelector.clickable(boolean)
     */
    public static @NonNull BySelector clickable(boolean isClickable) {
        return new BySelector().clickable(isClickable);
    }

    /**
     * Constructs a new {@link BySelector} and sets the enabled criteria.
     *
     * @see BySelector#enabled(boolean) BySelector.enabled(boolean)
     */
    public static @NonNull BySelector enabled(boolean isEnabled) {
        return new BySelector().enabled(isEnabled);
    }

    /**
     * Constructs a new {@link BySelector} and sets the focusable criteria.
     *
     * @see BySelector#focusable(boolean) BySelector.focusable(boolean)
     */
    public static @NonNull BySelector focusable(boolean isFocusable) {
        return new BySelector().focusable(isFocusable);
    }

    /**
     * Constructs a new {@link BySelector} and sets the focused criteria.
     *
     * @see BySelector#focused(boolean) BySelector.focused(boolean)
     */
    public static @NonNull BySelector focused(boolean isFocused) {
        return new BySelector().focused(isFocused);
    }

    /**
     * Constructs a new {@link BySelector} and sets the long clickable criteria.
     *
     * @see BySelector#longClickable(boolean) BySelector.longClickable(boolean)
     */
    public static @NonNull BySelector longClickable(boolean isLongClickable) {
        return new BySelector().longClickable(isLongClickable);
    }

    /**
     * Constructs a new {@link BySelector} and sets the scrollable criteria.
     *
     * @see BySelector#scrollable(boolean) BySelector.scrollable(boolean)
     */
    public static @NonNull BySelector scrollable(boolean isScrollable) {
        return new BySelector().scrollable(isScrollable);
    }

    /**
     * Constructs a new {@link BySelector} and sets the selected criteria.
     *
     * @see BySelector#selected(boolean) BySelector.selected(boolean)
     */
    public static @NonNull BySelector selected(boolean isSelected) {
        return new BySelector().selected(isSelected);
    }

    /**
     * Constructs a new {@link BySelector} and sets the depth criteria.
     */
    public static @NonNull BySelector depth(int depth) {
        return new BySelector().depth(depth);
    }

    /**
     * Constructs a new {@link BySelector} and sets the display ID criteria.
     *
     * @see BySelector#displayId(int) BySelector.displayId(int)
     */
    @RequiresApi(30)
    public static @NonNull BySelector displayId(int displayId) {
        return new BySelector().displayId(displayId);
    }

    /**
     * Constructs a new {@link BySelector} and adds a parent selector criteria.
     *
     * @see BySelector#hasParent(BySelector) BySelector.hasParent(BySelector)
     */
    public static @NonNull BySelector hasParent(@NonNull BySelector parentSelector) {
        return new BySelector().hasParent(parentSelector);
    }

    /**
     * Constructs a new {@link BySelector} and adds an ancestor selector criteria.
     *
     * @see BySelector#hasAncestor(BySelector) BySelector.hasAncestor(BySelector)
     */
    public static @NonNull BySelector hasAncestor(@NonNull BySelector ancestorSelector) {
        return new BySelector().hasAncestor(ancestorSelector);
    }

    /**
     * Constructs a new {@link BySelector} and adds an ancestor selector criteria.
     *
     * @see BySelector#hasAncestor(BySelector, int) BySelector.hasAncestor(BySelector, int)
     */
    public static @NonNull BySelector hasAncestor(@NonNull BySelector ancestorSelector,
            @IntRange(from = 1) int maxAncestorDistance) {
        return new BySelector().hasAncestor(ancestorSelector, maxAncestorDistance);
    }

    /**
     * Constructs a new {@link BySelector} and adds a child selector criteria.
     *
     * @see BySelector#hasChild(BySelector) BySelector.hasChild(BySelector)
     */
    public static @NonNull BySelector hasChild(@NonNull BySelector childSelector) {
        return new BySelector().hasChild(childSelector);
    }

    /**
     * Constructs a new {@link BySelector} and adds a descendant selector criteria.
     *
     * @see BySelector#hasDescendant(BySelector) BySelector.hasDescendant(BySelector)
     */
    public static @NonNull BySelector hasDescendant(@NonNull BySelector descendantSelector) {
        return new BySelector().hasDescendant(descendantSelector);
    }

    /**
     * Constructs a new {@link BySelector} and adds a descendant selector criteria.
     *
     * @see BySelector#hasDescendant(BySelector, int) BySelector.hasDescendant(BySelector, int)
     */
    public static @NonNull BySelector hasDescendant(@NonNull BySelector descendantSelector,
            int maxDepth) {
        return new BySelector().hasDescendant(descendantSelector, maxDepth);
    }

}