appium提供的滑动屏幕方法
# convenience method added to Appium (NOT Selenium 3)
def swipe(self, start_x, start_y, end_x, end_y, duration=None):
"""Swipe from one point to another point, for an optional duration.
:Args:
- start_x - x-coordinate at which to start
- start_y - y-coordinate at which to start
- end_x - x-coordinate at which to stop
- end_y - y-coordinate at which to stop
- duration - (optional) time to take the swipe, in ms.
:Usage:
driver.swipe(100, 100, 100, 400)
"""
用法:driver.swipe(200, 500,1000, 500, duration=500)
参数就是起点和终点x/y坐标
duration是滑动从起点到终点坐标所耗费的时间,单位是毫秒。
注意这个时间非常重要。正常速度滑动和快速滑动的效果是不一样的
这样用swipe同样存在的问题就是,兼容性不行。
如果换了屏幕,可能会有问题,比如有的屏幕是分辨率更低的,没有1000y坐标。就出问题了。
可以根据元素宽度和左上角坐标来计算出相对坐标
方法是先获:
ele = driver.find_element_by_id('com.huawei.appmarket:id/commodityLL')
location=ele.location#左上角坐标
size=ele.size#元素的高度和宽度
#计算起始点坐标
start_x=location['x']+int(size['width'])*0.2
start_y=location['y']+int(size['height'])*0.5
end_x=location['x']+int(size['width'])*0.8
end_y=