常用的一些API,具体的请参考API
-
导入设备
- 唯一一个设备
from uiautomator import device as d
- 1
- 导入具体设备
from uiautomator import Device d = Device('014E05DE0F02000E')
- 1
- 2
- 具体的设备和端口连接
from uiautomator import Device d = Device('014E05DE0F02000E', adb_server_host='192.168.1.68', adb_server_port=5037)
- 1
- 2
-
基础使用(d为获取设备)
#设备信息 d.info #打开屏幕 d.screen.on() # 关闭屏幕 d.screen.off() # 唤醒设备 d.wakeup() # 休眠 d.sleep()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 检查屏幕是否关闭
if d.screen == "on": # of d.screen != "off" # do something pass if d.screen == "off": # of d.screen != "on" # do something pass
- 1
- 2
- 3
- 4
- 5
- 6
#按Home键 d.press.home() # 按返回键 d.press.back() # 按返回键 d.press("back") # press keycode 0x07('0') with META ALT(0x02) on d.press(0x07, 0x02)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
-
手势操作
# 点击屏幕某一点 d.click(x, y) # 长点击屏幕某一点 d.long_click(x, y) # 滑动从一点 (sx, sy) 到另一点 (ex, ey) d.swipe(sx, sy, ex, ey) # 一点到另一点经过十步 d.swipe(sx, sy, ex, ey, steps=10) # 拖拽从一点到另一点 d.drag(sx, sy, ex, ey) # 一点到另一点经过十步 d.drag(sx, sy, ex, ey, steps=10)