@Deprecated public class UiObject extends Object
UiSelector
properties specified in
its constructor. Once you create an instance of a UiObject, it can
be reused for different views that match the selector criteria.Modifier and Type | Field and Description |
---|---|
protected static int |
FINGER_TOUCH_HALF_WIDTH
Deprecated.
|
protected static int |
SWIPE_MARGIN_LIMIT
Deprecated.
|
protected static long |
WAIT_FOR_EVENT_TMEOUT
Deprecated.
|
protected static long |
WAIT_FOR_SELECTOR_POLL
Deprecated.
|
protected static long |
WAIT_FOR_SELECTOR_TIMEOUT
Deprecated.
|
protected static long |
WAIT_FOR_WINDOW_TMEOUT
Deprecated.
|
Constructor and Description |
---|
UiObject(UiSelector selector)
Deprecated.
Constructs a UiObject to represent a view that matches the specified
selector criteria.
|
Modifier and Type | Method and Description |
---|---|
void |
clearTextField()
Deprecated.
Clears the existing text contents in an editable field.
|
boolean |
click()
Deprecated.
Performs a click at the center of the visible bounds of the UI element represented
by this UiObject.
|
boolean |
clickAndWaitForNewWindow()
Deprecated.
Waits for window transitions that would typically take longer than the
usual default timeouts.
|
boolean |
clickAndWaitForNewWindow(long timeout)
Deprecated.
Performs a click at the center of the visible bounds of the UI element represented
by this UiObject and waits for window transitions.
|
boolean |
clickBottomRight()
Deprecated.
Clicks the bottom and right corner of the UI element
|
boolean |
clickTopLeft()
Deprecated.
Clicks the top and left corner of the UI element
|
boolean |
dragTo(int destX,
int destY,
int steps)
Deprecated.
Drags this object to arbitrary coordinates.
|
boolean |
dragTo(UiObject destObj,
int steps)
Deprecated.
Drags this object to a destination UiObject.
|
boolean |
exists()
Deprecated.
Check if view exists.
|
protected AccessibilityNodeInfo |
findAccessibilityNodeInfo(long timeout)
Deprecated.
Finds a matching UI element in the accessibility hierarchy, by
using the selector for this UiObject.
|
Rect |
getBounds()
Deprecated.
Returns the view's
bounds property. |
UiObject |
getChild(UiSelector selector)
Deprecated.
Creates a new UiObject for a child view that is under the present UiObject.
|
int |
getChildCount()
Deprecated.
Counts the child views immediately under the present UiObject.
|
String |
getClassName()
Deprecated.
Retrieves the
className property of the UI element. |
String |
getContentDescription()
Deprecated.
Reads the
content_desc property of the UI element |
UiObject |
getFromParent(UiSelector selector)
Deprecated.
Creates a new UiObject for a sibling view or a child of the sibling view,
relative to the present UiObject.
|
String |
getPackageName()
Deprecated.
Reads the view's
package property |
UiSelector |
getSelector()
Deprecated.
Debugging helper.
|
String |
getText()
Deprecated.
Reads the
text property of the UI element |
Rect |
getVisibleBounds()
Deprecated.
Returns the visible bounds of the view.
|
boolean |
isCheckable()
Deprecated.
Checks if the UI element's
checkable property is currently true. |
boolean |
isChecked()
Deprecated.
Check if the UI element's
checked property is currently true |
boolean |
isClickable()
Deprecated.
Checks if the UI element's
clickable property is currently true. |
boolean |
isEnabled()
Deprecated.
Checks if the UI element's
enabled property is currently true. |
boolean |
isFocusable()
Deprecated.
Check if the UI element's
focusable property is currently true. |
boolean |
isFocused()
Deprecated.
Check if the UI element's
focused property is currently true |
boolean |
isLongClickable()
Deprecated.
Check if the view's
long-clickable property is currently true |
boolean |
isScrollable()
Deprecated.
Check if the view's
scrollable property is currently true |
boolean |
isSelected()
Deprecated.
Checks if the UI element's
selected property is currently true. |
boolean |
longClick()
Deprecated.
Long clicks the center of the visible bounds of the UI element
|
boolean |
longClickBottomRight()
Deprecated.
Long clicks bottom and right corner of the UI element
|
boolean |
longClickTopLeft()
Deprecated.
Long clicks on the top and left corner of the UI element
|
boolean |
performMultiPointerGesture(MotionEvent.PointerCoords[]... touches)
Deprecated.
Performs a multi-touch gesture.
|
boolean |
performTwoPointerGesture(Point startPoint1,
Point startPoint2,
Point endPoint1,
Point endPoint2,
int steps)
Deprecated.
Generates a two-pointer gesture with arbitrary starting and ending points.
|
boolean |
pinchIn(int percent,
int steps)
Deprecated.
Performs a two-pointer gesture, where each pointer moves diagonally
toward the other, from the edges to the center of this UiObject .
|
boolean |
pinchOut(int percent,
int steps)
Deprecated.
Performs a two-pointer gesture, where each pointer moves diagonally
opposite across the other, from the center out towards the edges of the
this UiObject.
|
boolean |
setText(String text)
Deprecated.
Sets the text in an editable field, after clearing the field's content.
|
boolean |
swipeDown(int steps)
Deprecated.
Performs the swipe down action on the UiObject.
|
boolean |
swipeLeft(int steps)
Deprecated.
Performs the swipe left action on the UiObject.
|
boolean |
swipeRight(int steps)
Deprecated.
Performs the swipe right action on the UiObject.
|
boolean |
swipeUp(int steps)
Deprecated.
Performs the swipe up action on the UiObject.
|
boolean |
waitForExists(long timeout)
Deprecated.
Waits a specified length of time for a view to become visible.
|
boolean |
waitUntilGone(long timeout)
Deprecated.
Waits a specified length of time for a view to become undetectable.
|
@Deprecated protected static final long WAIT_FOR_SELECTOR_TIMEOUT
Configurator.setWaitForSelectorTimeout(long)
protected static final long WAIT_FOR_SELECTOR_POLL
protected static final long WAIT_FOR_WINDOW_TMEOUT
protected static final int SWIPE_MARGIN_LIMIT
@Deprecated protected static final long WAIT_FOR_EVENT_TMEOUT
Configurator.setScrollAcknowledgmentTimeout(long)
protected static final int FINGER_TOUCH_HALF_WIDTH
public UiObject(UiSelector selector)
selector
- public final UiSelector getSelector()
getSelector().toString();
UiSelector
public UiObject getChild(UiSelector selector) throws UiObjectNotFoundException
selector
- for child view to matchUiObjectNotFoundException
public UiObject getFromParent(UiSelector selector) throws UiObjectNotFoundException
selector
- for a sibling view or children of the sibling viewUiObjectNotFoundException
public int getChildCount() throws UiObjectNotFoundException
UiObjectNotFoundException
protected AccessibilityNodeInfo findAccessibilityNodeInfo(long timeout)
timeout
- in millisecondspublic boolean dragTo(UiObject destObj, int steps) throws UiObjectNotFoundException
destObj
- the destination UiObject.steps
- usually 40 steps. You can increase or decrease the steps to change the speed.UiObjectNotFoundException
public boolean dragTo(int destX, int destY, int steps) throws UiObjectNotFoundException
destX
- the X-axis coordinate.destY
- the Y-axis coordinate.steps
- usually 40 steps. You can increase or decrease the steps to change the speed.UiObjectNotFoundException
public boolean swipeUp(int steps) throws UiObjectNotFoundException
steps
- indicates the number of injected move steps into the system. Steps are
injected about 5ms apart. So a 100 steps may take about 1/2 second to complete.UiObjectNotFoundException
public boolean swipeDown(int steps) throws UiObjectNotFoundException
steps
- indicates the number of injected move steps into the system. Steps are
injected about 5ms apart. So a 100 steps may take about 1/2 second to complete.UiObjectNotFoundException
public boolean swipeLeft(int steps) throws UiObjectNotFoundException
steps
- indicates the number of injected move steps into the system. Steps are
injected about 5ms apart. So a 100 steps may take about 1/2 second to complete.UiObjectNotFoundException
public boolean swipeRight(int steps) throws UiObjectNotFoundException
steps
- indicates the number of injected move steps into the system. Steps are
injected about 5ms apart. So a 100 steps may take about 1/2 second to complete.UiObjectNotFoundException
public boolean click() throws UiObjectNotFoundException
UiObjectNotFoundException
public boolean clickAndWaitForNewWindow() throws UiObjectNotFoundException
clickAndWaitForNewWindow(long)
UiObjectNotFoundException
public boolean clickAndWaitForNewWindow(long timeout) throws UiObjectNotFoundException
click()
only in that this method waits for a
a new window transition as a result of the click. Some examples of a window transition:
timeout
- timeout before giving up on waiting for a new windowUiObjectNotFoundException
public boolean clickTopLeft() throws UiObjectNotFoundException
UiObjectNotFoundException
public boolean longClickBottomRight() throws UiObjectNotFoundException
UiObjectNotFoundException
public boolean clickBottomRight() throws UiObjectNotFoundException
UiObjectNotFoundException
public boolean longClick() throws UiObjectNotFoundException
UiObjectNotFoundException
public boolean longClickTopLeft() throws UiObjectNotFoundException
UiObjectNotFoundException
public String getText() throws UiObjectNotFoundException
text
property of the UI elementUiObjectNotFoundException
- if no match could be foundpublic String getClassName() throws UiObjectNotFoundException
className
property of the UI element.UiObjectNotFoundException
- if no match was foundpublic String getContentDescription() throws UiObjectNotFoundException
content_desc
property of the UI elementUiObjectNotFoundException
public boolean setText(String text) throws UiObjectNotFoundException
UiSelector
selector of this object must reference a UI element that is editable.
When you call this method, the method first simulates a click()
on
editable field to set focus. The method then clears the field's contents
and injects your specified text into the field.
If you want to capture the original contents of the field, call getText()
first.
You can then modify the text and use this method to update the field.text
- string to setUiObjectNotFoundException
public void clearTextField() throws UiObjectNotFoundException
UiSelector
of this object must reference a UI element that is editable.
When you call this method, the method first sets focus at the start edge of the field.
The method then simulates a long-press to select the existing text, and deletes the
selected text.
If a "Select-All" option is displayed, the method will automatically attempt to use it
to ensure full text selection.
Note that it is possible that not all the text in the field is selected; for example,
if the text contains separators such as spaces, slashes, at symbol etc.
Also, not all editable fields support the long-press functionality.UiObjectNotFoundException
public boolean isChecked() throws UiObjectNotFoundException
checked
property is currently trueUiObjectNotFoundException
public boolean isSelected() throws UiObjectNotFoundException
selected
property is currently true.UiObjectNotFoundException
public boolean isCheckable() throws UiObjectNotFoundException
checkable
property is currently true.UiObjectNotFoundException
public boolean isEnabled() throws UiObjectNotFoundException
enabled
property is currently true.UiObjectNotFoundException
public boolean isClickable() throws UiObjectNotFoundException
clickable
property is currently true.UiObjectNotFoundException
public boolean isFocused() throws UiObjectNotFoundException
focused
property is currently trueUiObjectNotFoundException
public boolean isFocusable() throws UiObjectNotFoundException
focusable
property is currently true.UiObjectNotFoundException
public boolean isScrollable() throws UiObjectNotFoundException
scrollable
property is currently trueUiObjectNotFoundException
public boolean isLongClickable() throws UiObjectNotFoundException
long-clickable
property is currently trueUiObjectNotFoundException
public String getPackageName() throws UiObjectNotFoundException
package
propertyUiObjectNotFoundException
public Rect getVisibleBounds() throws UiObjectNotFoundException
UiObjectNotFoundException
#getBounds()}
public Rect getBounds() throws UiObjectNotFoundException
bounds
property. See getVisibleBounds()
UiObjectNotFoundException
public boolean waitForExists(long timeout)
timeout
- the amount of time to wait (in milliseconds)public boolean waitUntilGone(long timeout)
UiSelector
of the object is
unable to find a match because the element has either changed its state or is no
longer displayed.
You can use this method when attempting to wait for some long operation
to compete, such as downloading a large file or connecting to a remote server.timeout
- time to wait (in milliseconds)public boolean exists()
waitForExists(long)
with zero timeout. This
basically returns immediately whether the view represented by this UiObject
exists or not. If you need to wait longer for this view, then see
waitForExists(long)
.public boolean pinchOut(int percent, int steps) throws UiObjectNotFoundException
percent
- percentage of the object's diagonal length for the pinch gesturesteps
- the number of steps for the gesture. Steps are injected
about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete.true
if all touch events for this gesture are injected successfully,
false
otherwiseUiObjectNotFoundException
public boolean pinchIn(int percent, int steps) throws UiObjectNotFoundException
percent
- percentage of the object's diagonal length for the pinch gesturesteps
- the number of steps for the gesture. Steps are injected
about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete.true
if all touch events for this gesture are injected successfully,
false
otherwiseUiObjectNotFoundException
public boolean performTwoPointerGesture(Point startPoint1, Point startPoint2, Point endPoint1, Point endPoint2, int steps)
startPoint1
- start point of pointer 1startPoint2
- start point of pointer 2endPoint1
- end point of pointer 1endPoint2
- end point of pointer 2steps
- the number of steps for the gesture. Steps are injected
about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete.true
if all touch events for this gesture are injected successfully,
false
otherwisepublic boolean performMultiPointerGesture(MotionEvent.PointerCoords[]... touches)
MotionEvent.PointerCoords
. You can use this method to
specify complex gestures, like circles and irregular shapes, where each
pointer may take a different path.
To create a single point on a pointer's touch path:
PointerCoords p = new PointerCoords();
p.x = stepX;
p.y = stepY;
p.pressure = 1;
p.size = 1;
touches
- represents the pointers' paths. Each MotionEvent.PointerCoords
array represents a different pointer. Each MotionEvent.PointerCoords
in an
array element represents a touch point on a pointer's path.true
if all touch events for this gesture are injected successfully,
false
otherwise