1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import sys
import uiautomator2 as u2
import time
d = u2.connect(sys.argv[1])
# 滑动
# d.swipe(0, 692, 0, 0, duration=1)
for i in range(10): # 滑动10次
# 方法1:直接滑动
d.swipe(253, 984, 253, 752, duration=1)
# # 方法2:尝试通过元素滑动(更推荐)
# scrollable = d.xpath('//*[@scrollable="true"]').get()
# if scrollable:
# scrollable.swipe("up")
time.sleep(1.5) # 滑动间隔
print(f"已完成第 {i+1} 次滑动")
|
参数duration数值可调,也可去除,不过建议保留这个参数