public
class
UiObject2
extends Object
java.lang.Object | |
↳ | android.support.test.uiautomator.UiObject2 |
A UiObject2
represents a UI element. Unlike UiObject
, it is bound to a particular
view instance and can become stale if the underlying view object is destroyed. As a result, it
may be necessary to call findObject(BySelector)
to obtain a new
UiObject2
instance if the UI changes significantly.
Public methods | |
---|---|
void
|
clear()
Clears the text content if this object is an editable field. |
void
|
click()
Clicks on this object. |
void
|
click(long duration)
Performs a click on this object that lasts for |
<R>
R
|
clickAndWait(EventCondition<R> condition, long timeout)
Clicks on this object, and waits for the given condition to become true. |
void
|
drag(Point dest)
Drags this object to the specified location. |
void
|
drag(Point dest, int speed)
Drags this object to the specified location. |
boolean
|
equals(Object object)
|
UiObject2
|
findObject(BySelector selector)
Searches all elements under this object and returns the first object to match the criteria. |
List<UiObject2>
|
findObjects(BySelector selector)
Searches all elements under this object and returns all objects that match the criteria. |
boolean
|
fling(Direction direction, int speed)
Performs a fling gesture on this object. |
boolean
|
fling(Direction direction)
Performs a fling gesture on this object. |
String
|
getApplicationPackage()
Returns the package name of the app that this object belongs to. |
int
|
getChildCount()
Returns the number of child elements directly under this object. |
List<UiObject2>
|
getChildren()
Returns a collection of the child elements directly under this object. |
String
|
getClassName()
Returns the class name of the underlying |
String
|
getContentDescription()
Returns the content description for this object. |
UiObject2
|
getParent()
Returns this object's parent. |
String
|
getResourceName()
Returns the fully qualified resource name for this object's id. |
String
|
getText()
Returns the text value for this object. |
Rect
|
getVisibleBounds()
Returns the visible bounds of this object in screen coordinates. |
Point
|
getVisibleCenter()
Returns a point in the center of the visible bounds of this object. |
boolean
|
hasObject(BySelector selector)
Returns whether there is a match for the given criteria under this object. |
int
|
hashCode()
|
boolean
|
isCheckable()
Returns whether this object is checkable. |
boolean
|
isChecked()
Returns whether this object is checked. |
boolean
|
isClickable()
Returns whether this object is clickable. |
boolean
|
isEnabled()
Returns whether this object is enabled. |
boolean
|
isFocusable()
Returns whether this object is focusable. |
boolean
|
isFocused()
Returns whether this object is focused. |
boolean
|
isLongClickable()
Returns whether this object is long clickable. |
boolean
|
isScrollable()
Returns whether this object is scrollable. |
boolean
|
isSelected()
Returns whether this object is selected. |
void
|
longClick()
Performs a long click on this object. |
void
|
pinchClose(float percent)
Performs a pinch close gesture on this object. |
void
|
pinchClose(float percent, int speed)
Performs a pinch close gesture on this object. |
void
|
pinchOpen(float percent)
Performs a pinch open gesture on this object. |
void
|
pinchOpen(float percent, int speed)
Performs a pinch open gesture on this object. |
void
|
recycle()
Recycle this object. |
boolean
|
scroll(Direction direction, float percent, int speed)
Performs a scroll gesture on this object. |
boolean
|
scroll(Direction direction, float percent)
Performs a scroll gesture on this object. |
void
|
setGestureMargin(int margin)
Sets the margins used for gestures in pixels. |
void
|
setGestureMargins(int left, int top, int right, int bottom)
Sets the margins used for gestures in pixels. |
void
|
setText(String text)
Sets the text content if this object is an editable field. |
void
|
swipe(Direction direction, float percent, int speed)
Performs a swipe gesture on this object. |
void
|
swipe(Direction direction, float percent)
Performs a swipe gesture on this object. |
<R>
R
|
wait(UiObject2Condition<R> condition, long timeout)
Waits for given the |
<R>
R
|
wait(SearchCondition<R> condition, long timeout)
Waits for given the |
Inherited methods | |
---|---|
![]()
java.lang.Object
|
void clear ()
Clears the text content if this object is an editable field.
void click ()
Clicks on this object.
void click (long duration)
Performs a click on this object that lasts for duration
milliseconds.
Parameters | |
---|---|
duration |
long
|
R clickAndWait (EventCondition<R> condition, long timeout)
Clicks on this object, and waits for the given condition to become true.
Parameters | |
---|---|
condition |
EventCondition
|
timeout |
long
|
Returns | |
---|---|
R |
void drag (Point dest)
Drags this object to the specified location.
Parameters | |
---|---|
dest |
Point :
The end point that this object should be dragged to.
|
void drag (Point dest, int speed)
Drags this object to the specified location.
Parameters | |
---|---|
dest |
Point :
The end point that this object should be dragged to. |
speed |
int :
The speed at which to perform this gesture in pixels per second.
|
boolean equals (Object object)
Parameters | |
---|---|
object |
Object
|
Returns | |
---|---|
boolean |
UiObject2 findObject (BySelector selector)
Searches all elements under this object and returns the first object to match the criteria.
Parameters | |
---|---|
selector |
BySelector
|
Returns | |
---|---|
UiObject2 |
List<UiObject2> findObjects (BySelector selector)
Searches all elements under this object and returns all objects that match the criteria.
Parameters | |
---|---|
selector |
BySelector
|
Returns | |
---|---|
List<UiObject2> |
boolean fling (Direction direction, int speed)
Performs a fling gesture on this object.
Parameters | |
---|---|
direction |
Direction :
The direction in which to fling. |
speed |
int :
The speed at which to perform this gesture in pixels per second. |
Returns | |
---|---|
boolean |
Whether the object can still scroll in the given direction. |
boolean fling (Direction direction)
Performs a fling gesture on this object.
Parameters | |
---|---|
direction |
Direction :
The direction in which to fling. |
Returns | |
---|---|
boolean |
Whether the object can still scroll in the given direction. |
String getApplicationPackage ()
Returns the package name of the app that this object belongs to.
Returns | |
---|---|
String |
int getChildCount ()
Returns the number of child elements directly under this object.
Returns | |
---|---|
int |
List<UiObject2> getChildren ()
Returns a collection of the child elements directly under this object.
Returns | |
---|---|
List<UiObject2> |
String getClassName ()
Returns the class name of the underlying View
represented by this
object.
Returns | |
---|---|
String |
String getContentDescription ()
Returns the content description for this object.
Returns | |
---|---|
String |
String getResourceName ()
Returns the fully qualified resource name for this object's id.
Returns | |
---|---|
String |
String getText ()
Returns the text value for this object.
Returns | |
---|---|
String |
Rect getVisibleBounds ()
Returns the visible bounds of this object in screen coordinates.
Returns | |
---|---|
Rect |
Point getVisibleCenter ()
Returns a point in the center of the visible bounds of this object.
Returns | |
---|---|
Point |
boolean hasObject (BySelector selector)
Returns whether there is a match for the given criteria under this object.
Parameters | |
---|---|
selector |
BySelector
|
Returns | |
---|---|
boolean |
int hashCode ()
Returns | |
---|---|
int |
boolean isCheckable ()
Returns whether this object is checkable.
Returns | |
---|---|
boolean |
boolean isChecked ()
Returns whether this object is checked.
Returns | |
---|---|
boolean |
boolean isClickable ()
Returns whether this object is clickable.
Returns | |
---|---|
boolean |
boolean isEnabled ()
Returns whether this object is enabled.
Returns | |
---|---|
boolean |
boolean isFocusable ()
Returns whether this object is focusable.
Returns | |
---|---|
boolean |
boolean isFocused ()
Returns whether this object is focused.
Returns | |
---|---|
boolean |
boolean isLongClickable ()
Returns whether this object is long clickable.
Returns | |
---|---|
boolean |
boolean isScrollable ()
Returns whether this object is scrollable.
Returns | |
---|---|
boolean |
boolean isSelected ()
Returns whether this object is selected.
Returns | |
---|---|
boolean |
void longClick ()
Performs a long click on this object.
void pinchClose (float percent)
Performs a pinch close gesture on this object.
Parameters | |
---|---|
percent |
float :
The size of the pinch as a percentage of this object's size.
|
void pinchClose (float percent, int speed)
Performs a pinch close gesture on this object.
Parameters | |
---|---|
percent |
float :
The size of the pinch as a percentage of this object's size. |
speed |
int :
The speed at which to perform this gesture in pixels per second.
|
void pinchOpen (float percent)
Performs a pinch open gesture on this object.
Parameters | |
---|---|
percent |
float :
The size of the pinch as a percentage of this object's size.
|
void pinchOpen (float percent, int speed)
Performs a pinch open gesture on this object.
Parameters | |
---|---|
percent |
float :
The size of the pinch as a percentage of this object's size. |
speed |
int :
The speed at which to perform this gesture in pixels per second.
|
void recycle ()
Recycle this object.
boolean scroll (Direction direction, float percent, int speed)
Performs a scroll gesture on this object.
Parameters | |
---|---|
direction |
Direction :
The direction in which to scroll. |
percent |
float :
The distance to scroll as a percentage of this object's visible size. |
speed |
int :
The speed at which to perform this gesture in pixels per second. |
Returns | |
---|---|
boolean |
Whether the object can still scroll in the given direction. |
boolean scroll (Direction direction, float percent)
Performs a scroll gesture on this object.
Parameters | |
---|---|
direction |
Direction :
The direction in which to scroll. |
percent |
float :
The distance to scroll as a percentage of this object's visible size. |
Returns | |
---|---|
boolean |
Whether the object can still scroll in the given direction. |
void setGestureMargin (int margin)
Sets the margins used for gestures in pixels.
Parameters | |
---|---|
margin |
int
|
void setGestureMargins (int left, int top, int right, int bottom)
Sets the margins used for gestures in pixels.
Parameters | |
---|---|
left |
int
|
top |
int
|
right |
int
|
bottom |
int
|
void setText (String text)
Sets the text content if this object is an editable field.
Parameters | |
---|---|
text |
String
|
void swipe (Direction direction, float percent, int speed)
Performs a swipe gesture on this object.
Parameters | |
---|---|
direction |
Direction :
The direction in which to swipe. |
percent |
float :
The length of the swipe as a percentage of this object's size. |
speed |
int :
The speed at which to perform this gesture in pixels per second.
|
void swipe (Direction direction, float percent)
Performs a swipe gesture on this object.
Parameters | |
---|---|
direction |
Direction :
The direction in which to swipe. |
percent |
float :
The length of the swipe as a percentage of this object's size.
|
R wait (UiObject2Condition<R> condition, long timeout)
Waits for given the condition
to be met.
Parameters | |
---|---|
condition |
UiObject2Condition :
The UiObject2Condition to evaluate. |
timeout |
long :
Maximum amount of time to wait in milliseconds. |
Returns | |
---|---|
R |
The final result returned by the condition. |
R wait (SearchCondition<R> condition, long timeout)
Waits for given the condition
to be met.
Parameters | |
---|---|
condition |
SearchCondition :
The SearchCondition to evaluate. |
timeout |
long :
Maximum amount of time to wait in milliseconds. |
Returns | |
---|---|
R |
The final result returned by the condition. |