滑动

swipe 滑动

语法

driver.swipe(x1, y1, x2, y2, 1000)

由坐标(x1,y1)滑动到坐标(x2,y2)处,持续时间1秒

坐标获取技巧

_可同过get_devices_size()得到荧幕宽高后,在分别乘以一个0.X的浮点数则可得到一坐标_

1
2
3
4
x = driver.get_window_size()['width']
y = driver.get_window_size()['height']
x1 = int(x*0.9)
y1 = int(y*0.5)

具体事例

由右向左滑动两次

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from appium_test.capability import driver
import time

def get_devices_size():
x = driver.get_window_size()['width']
y = driver.get_window_size()['height']
return x, y

def swipeLeft():
l = get_devices_size()
x1 = int(l[0]*0.9)
x2 = int(l[0]*0.1)
y1 = int(l[1]*0.5)
driver.swipe(x1, y1, x2, y1, 1000)

for i in range(2):
swipeLeft()
time.sleep(0.5)