📱 Android UI 自动化 (uiautomator2)
电脑和手机需要在同一局域网环境下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# coding: utf-8
import uiautomator2 as u2
import os
# 连接设备
def connect_device():
"""通过adb连接设备"""
tmp = os.popen('adb devices')
serial_number = tmp.readlines()[1].split()[0]
return u2.connect(serial_number)
# 初始化设备连接
d = connect_device()
# 返回主页
d.press('home')
d.sleep(0.1)
d.press('home')
d.sleep(1)
# 获取屏幕尺寸并滑动
x, y = d.window_size()
x1 = x * 0.9
y1 = y * 0.5
x2 = x * 0.1
d.swipe(x1, y1, x2, y1)
d.sleep(1)
# 点击文件夹
try:
d.xpath('//*[@content-desc="文件夹:amuse"]/android.widget.ImageView[1]').click()
except:
d.xpath('//*[@content-desc="amuse 小文件夹"]/android.widget.ImageView[1]').click()
# 点击应用
d(text='命运-冠位指定').click()
d.sleep(1)
d.click(0.37, 0.776)
# 停止应用
d.app_stop("com.bilibili.fgo.uc")
d.uiautomator.stop()
|
游戏自动化 adb
1
2
3
4
5
|
adb shell input keyevent 3 # home键
adb shell input keyevent 4 # 返回键
adb shell input tap x y # 触击屏幕第x行,第y列的点
adb shell getprop ro.product.model # 获取手机型号
adb shell wm size # 获取屏幕分辨率
|
pip3 install weditor==0.6.3