-
1、选择:d(text=‘Clock‘, className=‘android.widget.TextView‘)
-
2、获取孩子或孙子:d( className = “ android.widget.ListView ”).child( text = “ Bluetooth ”)
-
3、兄弟姐妹:d(text="Google").sibling(className="android.widget.ImageView")
-
4、获取子节点根据文本:d(className="android.widget.ListView", resourceId="android:id/list") \
-
.child_by_text("Bluetooth", className="android.widget.LinearLayout")
-
5、获取子节点根据文本允许滚动搜素:d(className="android.widget.ListView", resourceId="android:id/list") \
-
.child_by_text("Bluetooth",allow_scroll_search=True,className="android.widget.LinearLayout")
-
6、支持多级:d(className = “ android.widget.ListView ”,resourceId = “ android:id / list ”)\
-
.child_by_text(“ Wi-Fi ”,className = “ android.widget.LinearLayout ”)\
-
.child(className = “ android .widget.Switch “)\ .click
-
()
-
7、支持相对定位:
-
? d(A).left(B),在A的左侧选择B.
-
? d(A).right(B),在A的右侧选择B.
-
? d(A).up(B),在A之上选择B.
-
? d(A).down(B),在A下选择B.
-
d(text="Wi?Fi").right(className="android.widget.Switch").click()
-
8、第一个文本带有“Add new”的实例:d(text = “ Add new ”,instance = 0)
-
9、在屏幕上查找:d(text="Add new").count
-
d(text="Add new”)[0]#第一个
-
d(text="Add new”)[1]#第二个
-
10、显示控件信息:view.info
-
11、检查控件是否存在:d(text = “ Settings ”).exists或者d.exists(text = “ Settings ”)
-
12、检查控件信息:d(text = “设置”).info
-
13、文本控件操作:
-
d(text = “ Settings ”).get_text() #获取小部件文本
-
d(text = “ Settings ”).set_text(“ My text ... ”) #设置文本
-
d(text = “ Settings ”).clear_text ) #清除文字
-
14、点击:
-
d( text = “ Settings ”).click()
-
#等待元素出现最多10秒钟,然后点击
-
d( text = “ Settings ”).click( timeout = 10)
-
#点击的别名
-
d(文本= “设置”).tap()
-
15、长按:d( text = “ Settings ”).long_click()
-
16、拖动元素到另一个位子:
-
d( text = “ Settings ”).drag_to(x,y, duration = 0.5)
-
d( text = “ Settings ”).drag_to( text = “ Clock ”, duration = 0.25)#clock的中心点
-
17、从一点到另一点的两点手势
-
d(text = “ Settings ”).gesture((sx1,sy1),(sx2,sy2),(ex1,ey1),(ex2,ey2))
-
18、特定UI对象上的两点手势
-
? In,从边缘到中心
-
? Out,从中心到边缘
-
#从边缘到中心。这里是“以”不“在”
-
d(text="Settings").pinch_in(percent=100, steps=10)
-
#从中心到边缘
-
d(text="Settings").pinch_out()
-
19、等待ui出现或消失
-
d(text="Settings").wait(timeout=3.0) # return bool
-
d(text="Settings").wait_gone(timeout=1.0)
-
20、#设置默认元素等待超时(秒)
-
d.wait_timeout = 30.0
-
21、控件不知道控件的情况下
-
d.set_fastinput_ime(True)#切换成FastInputIME输入法
-
d.send_keys(“你好123abcEFG ”)# adb广播输入
-
d.clear_text()#清除输入框所有内容(需要android-uiautomator.apk版本> = 1.0.7 )
-
d.set_fastinput_ime(False)#切换成正常的输入法
-
22、显示:Toast
-
d.make_toast("Hello world")
-
d.make_toast("Hello world", 1.5) # show for 1.5s