Summary: Methods | Inherited Methods | [Expand All]

# By

`public class By`
`extends Object` ``

java.lang.Object
↳ | android.support.test.uiautomator.By

`By` is a utility class which enables the creation of `BySelector`s in a concise manner.

Its primary function is to provide static factory methods for constructing `BySelector`s 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 BySelector` | `checkable(boolean isCheckable)` Constructs a new `BySelector` and sets the checkable criteria.
`static BySelector` | `checked(boolean isChecked)` Constructs a new `BySelector` and sets the checked criteria.
`static BySelector` | `clazz(String packageName, String className)` Constructs a new `BySelector` and sets the class name criteria.
`static BySelector` | `clazz(Class clazz)` Constructs a new `BySelector` and sets the class name criteria.
`static BySelector` | `clazz(Pattern className)` Constructs a new `BySelector` and sets the class name criteria.
`static BySelector` | `clazz(String className)` Constructs a new `BySelector` and sets the class name criteria.
`static BySelector` | `clickable(boolean isClickable)` Constructs a new `BySelector` and sets the clickable criteria.
`static BySelector` | `copy(BySelector original)` Constructs a new `BySelector` and copies the criteria from `original`.
`static BySelector` | `depth(int depth)` Constructs a new `BySelector` and sets the depth criteria.
`static BySelector` | `desc(String contentDescription)` Constructs a new `BySelector` and sets the content description criteria.
`static BySelector` | `desc(Pattern contentDescription)` Constructs a new `BySelector` and sets the content description criteria.
`static BySelector` | `descContains(String substring)` Constructs a new `BySelector` and sets the content description criteria.
`static BySelector` | `descEndsWith(String substring)` Constructs a new `BySelector` and sets the content description criteria.
`static BySelector` | `descStartsWith(String substring)` Constructs a new `BySelector` and sets the content description criteria.
`static BySelector` | `enabled(boolean isEnabled)` Constructs a new `BySelector` and sets the enabled criteria.
`static BySelector` | `focusable(boolean isFocusable)` Constructs a new `BySelector` and sets the focusable criteria.
`static BySelector` | `focused(boolean isFocused)` Constructs a new `BySelector` and sets the focused criteria.
`static BySelector` | `hasChild(BySelector childSelector)` Constructs a new `BySelector` and adds a child selector criteria.
`static BySelector` | `hasDescendant(BySelector descendantSelector)` Constructs a new `BySelector` and adds a descendant selector criteria.
`static BySelector` | `hasDescendant(BySelector descendantSelector, int maxDepth)` Constructs a new `BySelector` and adds a descendant selector criteria.
`static BySelector` | `longClickable(boolean isLongClickable)` Constructs a new `BySelector` and sets the long clickable criteria.
`static BySelector` | `pkg(Pattern applicationPackage)` Constructs a new `BySelector` and sets the application package name criteria.
`static BySelector` | `pkg(String applicationPackage)` Constructs a new `BySelector` and sets the application package name criteria.
`static BySelector` | `res(String resourceName)` Constructs a new `BySelector` and sets the resource name criteria.
`static BySelector` | `res(String resourcePackage, String resourceId)` Constructs a new `BySelector` and sets the resource name criteria.
`static BySelector` | `res(Pattern resourceName)` Constructs a new `BySelector` and sets the resource id criteria.
`static BySelector` | `scrollable(boolean isScrollable)` Constructs a new `BySelector` and sets the scrollable criteria.
`static BySelector` | `selected(boolean isSelected)` Constructs a new `BySelector` and sets the selected criteria.
`static BySelector` | `text(Pattern regex)` Constructs a new `BySelector` and sets the text value criteria.
`static BySelector` | `text(String text)` Constructs a new `BySelector` and sets the text value criteria.
`static BySelector` | `textContains(String substring)` Constructs a new `BySelector` and sets the text value criteria.
`static BySelector` | `textEndsWith(String substring)` Constructs a new `BySelector` and sets the text value criteria.
`static BySelector` | `textStartsWith(String substring)` Constructs a new `BySelector` and sets the text value criteria.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()`
`boolean` | `equals(Object arg0)`
`void` | `finalize()`
`final Class<?>` | `getClass()`
`int` | `hashCode()`
`final void` | `notify()`
`final void` | `notifyAll()`
`String` | `toString()`
`final void` | `wait(long arg0, int arg1)`
`final void` | `wait(long arg0)`
`final void` | `wait()`

## Public methods

### checkable

    BySelector checkable (boolean isCheckable)

Constructs a new `BySelector` and sets the checkable criteria.

Parameters
`isCheckable` | `boolean`

Returns
`BySelector` |

See also:

- `checkable(boolean)`

### checked

    BySelector checked (boolean isChecked)

Constructs a new `BySelector` and sets the checked criteria.

Parameters
`isChecked` | `boolean`

Returns
`BySelector` |

See also:

- `checked(boolean)`

### clazz

    BySelector clazz (String packageName,
                    String className)

Constructs a new `BySelector` and sets the class name criteria.

Parameters
`packageName` | `String`
`className` | `String`

Returns
`BySelector` |

See also:

- `clazz(String, String)`

### clazz

    BySelector clazz (Class clazz)

Constructs a new `BySelector` and sets the class name criteria.

Parameters
`clazz` | `Class`

Returns
`BySelector` |

See also:

- `clazz(Class)`

### clazz

    BySelector clazz (Pattern className)

Constructs a new `BySelector` and sets the class name criteria.

Parameters
`className` | `Pattern`

Returns
`BySelector` |

See also:

- `clazz(Pattern)`

### clazz

    BySelector clazz (String className)

Constructs a new `BySelector` and sets the class name criteria.

Parameters
`className` | `String`

Returns
`BySelector` |

See also:

- `clazz(String)`

### clickable

    BySelector clickable (boolean isClickable)

Constructs a new `BySelector` and sets the clickable criteria.

Parameters
`isClickable` | `boolean`

Returns
`BySelector` |

See also:

- `clickable(boolean)`

### copy

    BySelector copy (BySelector original)

Constructs a new `BySelector` and copies the criteria from `original`.

Parameters
`original` | `BySelector`

Returns
`BySelector` |

### depth

    BySelector depth (int depth)

Constructs a new `BySelector` and sets the depth criteria.

Parameters
`depth` | `int`

Returns
`BySelector` |

### desc

    BySelector desc (String contentDescription)

Constructs a new `BySelector` and sets the content description criteria.

Parameters
`contentDescription` | `String`

Returns
`BySelector` |

See also:

- `desc(String)`

### desc

    BySelector desc (Pattern contentDescription)

Constructs a new `BySelector` and sets the content description criteria.

Parameters
`contentDescription` | `Pattern`

Returns
`BySelector` |

See also:

- `desc(Pattern)`

### descContains

    BySelector descContains (String substring)

Constructs a new `BySelector` and sets the content description criteria.

Parameters
`substring` | `String`

Returns
`BySelector` |

See also:

- `descContains(String)`

### descEndsWith

    BySelector descEndsWith (String substring)

Constructs a new `BySelector` and sets the content description criteria.

Parameters
`substring` | `String`

Returns
`BySelector` |

See also:

- `descEndsWith(String)`

### descStartsWith

    BySelector descStartsWith (String substring)

Constructs a new `BySelector` and sets the content description criteria.

Parameters
`substring` | `String`

Returns
`BySelector` |

See also:

- `descStartsWith(String)`

### enabled

    BySelector enabled (boolean isEnabled)

Constructs a new `BySelector` and sets the enabled criteria.

Parameters
`isEnabled` | `boolean`

Returns
`BySelector` |

See also:

- `enabled(boolean)`

### focusable

    BySelector focusable (boolean isFocusable)

Constructs a new `BySelector` and sets the focusable criteria.

Parameters
`isFocusable` | `boolean`

Returns
`BySelector` |

See also:

- `focusable(boolean)`

### focused

    BySelector focused (boolean isFocused)

Constructs a new `BySelector` and sets the focused criteria.

Parameters
`isFocused` | `boolean`

Returns
`BySelector` |

See also:

- `focused(boolean)`

### hasChild

    BySelector hasChild (BySelector childSelector)

Constructs a new `BySelector` and adds a child selector criteria.

Parameters
`childSelector` | `BySelector`

Returns
`BySelector` |

See also:

- `hasChild(BySelector)`

### hasDescendant

    BySelector hasDescendant (BySelector descendantSelector)

Constructs a new `BySelector` and adds a descendant selector criteria.

Parameters
`descendantSelector` | `BySelector`

Returns
`BySelector` |

See also:

- `hasDescendant(BySelector)`

### hasDescendant

    BySelector hasDescendant (BySelector descendantSelector,
                    int maxDepth)

Constructs a new `BySelector` and adds a descendant selector criteria.

Parameters
`descendantSelector` | `BySelector`
`maxDepth` | `int`

Returns
`BySelector` |

See also:

- `hasDescendant(BySelector, int)`

### longClickable

    BySelector longClickable (boolean isLongClickable)

Constructs a new `BySelector` and sets the long clickable criteria.

Parameters
`isLongClickable` | `boolean`

Returns
`BySelector` |

See also:

- `longClickable(boolean)`

### pkg

    BySelector pkg (Pattern applicationPackage)

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

Parameters
`applicationPackage` | `Pattern`

Returns
`BySelector` |

See also:

- `pkg(Pattern)`

### pkg

    BySelector pkg (String applicationPackage)

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

Parameters
`applicationPackage` | `String`

Returns
`BySelector` |

See also:

- `pkg(String)`

### res

    BySelector res (String resourceName)

Constructs a new `BySelector` and sets the resource name criteria.

Parameters
`resourceName` | `String`

Returns
`BySelector` |

See also:

- `res(String)`

### res

    BySelector res (String resourcePackage,
                    String resourceId)

Constructs a new `BySelector` and sets the resource name criteria.

Parameters
`resourcePackage` | `String`
`resourceId` | `String`

Returns
`BySelector` |

See also:

- `res(String, String)`

### res

    BySelector res (Pattern resourceName)

Constructs a new `BySelector` and sets the resource id criteria.

Parameters
`resourceName` | `Pattern`

Returns
`BySelector` |

See also:

- `res(Pattern)`

### scrollable

    BySelector scrollable (boolean isScrollable)

Constructs a new `BySelector` and sets the scrollable criteria.

Parameters
`isScrollable` | `boolean`

Returns
`BySelector` |

See also:

- `scrollable(boolean)`

### selected

    BySelector selected (boolean isSelected)

Constructs a new `BySelector` and sets the selected criteria.

Parameters
`isSelected` | `boolean`

Returns
`BySelector` |

See also:

- `selected(boolean)`

### text

    BySelector text (Pattern regex)

Constructs a new `BySelector` and sets the text value criteria.

Parameters
`regex` | `Pattern`

Returns
`BySelector` |

See also:

- `text(Pattern)`

### text

    BySelector text (String text)

Constructs a new `BySelector` and sets the text value criteria.

Parameters
`text` | `String`

Returns
`BySelector` |

See also:

- `text(String)`

### textContains

    BySelector textContains (String substring)

Constructs a new `BySelector` and sets the text value criteria.

Parameters
`substring` | `String`

Returns
`BySelector` |

See also:

- `textContains(String)`

### textEndsWith

    BySelector textEndsWith (String substring)

Constructs a new `BySelector` and sets the text value criteria.

Parameters
`substring` | `String`

Returns
`BySelector` |

See also:

- `textEndsWith(String)`

### textStartsWith

    BySelector textStartsWith (String substring)

Constructs a new `BySelector` and sets the text value criteria.

Parameters
`substring` | `String`

Returns
`BySelector` |

See also:

- `textStartsWith(String)`

- ## Interfaces

  - IAutomationSupport
  - UiWatcher

- ## Classes

  - By
  - BySelector
  - Configurator
  - EventCondition
  - SearchCondition
  - UiAutomatorInstrumentationTestRunner
  - UiAutomatorTestCase
  - UiCollection
  - UiDevice
  - UiObject
  - UiObject2
  - UiObject2Condition
  - UiScrollable
  - UiSelector
  - Until

- ## Enums

  - Direction

- ## Exceptions

  - StaleObjectException
  - UiObjectNotFoundException