public interface UiElement
UI elements are generally views. Users can get attributes and perform actions. Note that actions often update UiElement, so users are advised not to store instances for later use -- the instances could become stale.
Modifier and Type | Field and Description |
---|---|
static Predicate<UiElement> |
VISIBLE
Filters out invisible children.
|
Modifier and Type | Method and Description |
---|---|
void |
click()
Clicks this element.
|
void |
doubleClick()
Double-clicks this element.
|
<T> T |
get(Attribute attribute) |
android.graphics.Rect |
getBounds()
Gets the UiElement bounds in screen coordinates.
|
java.util.List<? extends UiElement> |
getChildren(Predicate<? super UiElement> predicate)
Gets an immutable
List of immediate children that satisfy
predicate . |
java.lang.String |
getClassName()
Gets the class name of the underlying view.
|
java.lang.String |
getContentDescription()
Gets the content description of this element.
|
InputInjector |
getInjector()
Gets the
InputInjector for injecting InputEvent. |
java.lang.String |
getPackageName()
Gets the package name of this element.
|
UiElement |
getParent()
Gets the parent.
|
java.lang.String |
getResourceId()
Gets the resource id of this element.
|
java.lang.String |
getText()
Gets the text of this element.
|
android.graphics.Rect |
getVisibleBounds()
Gets the UiElement bounds in screen coordinates.
|
boolean |
isCheckable() |
boolean |
isChecked() |
boolean |
isClickable() |
boolean |
isEnabled() |
boolean |
isFocusable() |
boolean |
isFocused() |
boolean |
isLongClickable() |
boolean |
isPassword() |
boolean |
isScrollable() |
boolean |
isSelected() |
boolean |
isVisible() |
void |
longClick()
Long-clicks this element.
|
boolean |
perform(Action action)
Executes the given action.
|
void |
scroll(Direction.PhysicalDirection direction)
Scrolls in the given direction.
|
void |
setText(java.lang.String text)
Sets the text of this element.
|
java.lang.String getText()
java.lang.String getContentDescription()
java.lang.String getClassName()
java.lang.String getResourceId()
java.lang.String getPackageName()
boolean isVisible()
boolean isCheckable()
boolean isChecked()
boolean isClickable()
boolean isEnabled()
boolean isFocusable()
boolean isFocused()
boolean isScrollable()
boolean isLongClickable()
boolean isPassword()
boolean isSelected()
android.graphics.Rect getBounds()
android.graphics.Rect getVisibleBounds()
<T> T get(Attribute attribute)
boolean perform(Action action)
action
- the action to executevoid setText(java.lang.String text)
If this element already has text, it is cleared first if the device has API 11 or higher.
TODO: Support this behavior on older devices.
The IME
(soft keyboard) may be shown after this call. If the text
ends with '\n'
, the
IME may be closed automatically. If the IME is open, you can call UiDevice.pressBack()
to close it.
If you are using InstrumentationDriver
,
you may use CloseKeyboardAction
to close it. The
advantage of CloseKeyboardAction
is that it is a no-op if the IME is hidden. This is
useful when the state of the IME cannot be determined.
text
- the text to entervoid click()
void longClick()
void doubleClick()
void scroll(Direction.PhysicalDirection direction)
direction
- specifies where the view port will move instead of the fingerjava.util.List<? extends UiElement> getChildren(Predicate<? super UiElement> predicate)
List
of immediate children that satisfy
predicate
. It always filters children that are null. This gives a
low level access to the underlying data. Do not use it unless you are sure
about the subtle details. Note the count may not be what you expect. For
instance, a dynamic list may show more items when scrolling beyond the end,
varying the count. The count also depends on the driver implementation:
InstrumentationDriver
includes all.UiAutomationDriver
depends on)
does not include off-screen children, but may include invisible on-screen
children.
Another discrepancy between InstrumentationDriver
UiAutomationDriver
is the order of children. The Accessibility API
returns children in the order of layout (see
ViewGroup.addChildrenForAccessibility(java.util.ArrayList<android.view.View>)
, which is added
in API16).
UiElement getParent()
InputInjector getInjector()
InputInjector
for injecting InputEvent.