一、实现原理
1.swipe函数使用方法
driver.swipe(x1, y1, x2, y2, t)
(X1,Y1):滑动起始点的坐标
(X2,Y2):滑动结束点的坐标
t:完成滑动所需要的时间,单位为ms,默认为空,可不填。
2.由于不同尺寸的屏幕,长宽以及屏幕分辨率不同,因此滑动起始结束点的坐标使用屏幕比例的方式确定。
上下滑动:X点坐标为屏幕横向长度的50%,即屏幕中间,Y点坐标分别为屏幕高度的25%和75%,即屏幕的高度的1/4(A)处和3/4(B)处;
向下滑动,从A点滑到B点
向上滑动,从B点滑到A点
![](https://img-blog.csdnimg.cn/20190422010720291.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTMyNTAwNzE=,size_16,color_FFFFFF,t_70)
左右滑动:Y点坐标为屏幕竖向高度的50%,即屏幕中间,X点坐标分别为屏幕宽度的25%和75%,即屏幕的宽度的1/4(C)处和3/4(D)处;
向右滑动,从C点滑到D点
向左滑动,从D点滑到C点
![](https://img-blog.csdnimg.cn/20190422010730435.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTMyNTAwNzE=,size_16,color_FFFFFF,t_70)
二、实现代码
class Slide:
def __init__(self, driver):
self.driver = driver
def get_screen_size(self):
x = self.driver.get_window_size()['width'] # 获取屏幕宽度
y = self.driver.get_window_size()['height'] # 获取屏幕高度
return (x, y)
def swipeLeft(self):
l = self.get_screen_size()
x1 = int(l[0] * 0.75)
y1 = int(l[1] * 0.5)
x2 = int(l[0] * 0.25)
self.driver.swipe(x1, y1, x2, y1)
print('向左滑动')
def swipeRight(self):
l = self.get_screen_size()
x1 = int(l[0] * 0.25)
y1 = int(l[1] * 0.5)
x2 = int(l[0] * 0.75)
self.driver.swipe(x1, y1, x2, y1)
print('向右滑动')
def swipeUp(self):
l = self.get_screen_size()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.75)
y2 = int(l[1] * 0.25)
self.driver.swipe(x1,y1,x1,y2)
print('向上滑动')
def swipeDown(self):
l = self.get_screen_size()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.25)
y2 = int(l[1] * 0.75)
self.driver.swipe(x1, y1, x1, y2)
print('向下滑动')
|