1.点击与长按
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 | longClick() Performs a long click on this object. |
2.拖拽与滑动
void | drag(Point dest) Drags this object to the specified location. |
void | drag(Point dest, int speed) Drags this object to the specified location. |
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. |
3.输入文本与清除文本
void | setText(String text) Sets the text content if this object is an editable field. |
void | clear() Clears the text content if this object is an editable field. |
如clear()不起作用,可采取
//将光标移动到文字末尾,按backspace
//将光标移动到文本开头,按del
4.获取对象属性
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. |
5.属性判断:
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. |
6.模拟手势操作
双指缩放
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. |
其他
boolean | fling(Direction direction, int speed) Performs a fling gesture on this object. |
boolean | fling(Direction direction) Performs a fling gesture on 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. |
7.判断对象是否存在
boolean | hasObject(BySelector selector) Returns whether there is a match for the given criteria under this object. |
8.获取该对象
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. |
9.等待
<R> R | wait(UiObject2Condition<R> condition, long timeout) Waits for given the |
<R> R | wait(SearchCondition<R> condition, long timeout) Waits for given the |