appium + Python + iOS 滑屏方法(appium版本大于1.5)

之前一直在搞android的自动化,滑动操作一直都用swipe(),比如:

he1 = int(dr.get_window_size()['height'] * 0.8)
he2 = int(dr.get_window_size()['height'] * 0.2)
wd1 = int(dr.get_window_size()['width'] * 0.2)
wd2 = int(dr.get_window_size()['width'] * 0.2)
dr.swipe(wd1, he1, wd2, he2, 1100) 
 
iOS想上滑翻页时同样的swipe无效报错,网上找了半天最终放弃了swipe,以下是几个比较靠谱的滑动方法:
第一种方式:
dr.execute_script('mobile: scroll', {'direction': 'down'})
###这种方式不仅滑动两次,还是反的,down是向上滑动,速度较慢

第二种方式:
dr.execute_script('mobile: swipe', {'direction': 'up'})
###向上滑动一屏,速度较快,但不能自定义滑动距离

第三种方式:
dr.execute_script("mobile:dragFromToForDuration", {"duration": 0.5, "element": None, "fromX": wd1, "fromY": he1, "toX": wd2, "toY": he2})
###这个比较靠谱,速度快,可以自定义滑动距离,还可以在某个元素上滑动,缺点:如果是元素的话,滑动前会点击一次,若元素有点击事件的话比较麻烦


 
posted @ 2018-11-30 15:33  drewgg  阅读(1278)  评论(0编辑  收藏  举报