APPium+Python+iOS使用execute_script() 屏幕滑动方法对比

最近在学习appium自动化,对iOS手机进行滑动操作进行总结:
1、mobile:scroll
向下滚动整个屏幕
driver.execute_script('mobile: scroll', {'direction': 'down'})
向上滚动整个屏幕
driver.execute_script('mobile: scroll', {'direction': 'up'})
向左滚动整个屏幕
driver.execute_script('mobile: scroll', {'direction': 'left'})
向右滚动整个屏幕
driver.execute_script('mobile: scroll', {'direction': 'right'})
该方法在实际使用调用时,会滚动2次。执行时间很长。

2、mobile:swipe
向下滚动屏幕
driver.execute_script('mobile: scroll', {'direction': 'up'})
向上滚动屏幕
driver.execute_script('mobile: scroll', {'direction': 'down'})
向右滚动屏幕
driver.execute_script('mobile: scroll', {'direction': 'left'})
向左滚动屏幕
driver.execute_script('mobile: scroll', {'direction': 'right'})
该方法在调用过程中,执行速度快,滑动屏幕距离短

3、mobile:dragFromToForDuration
duration: 浮点数范围[0.5,60]。表示开始拖动点之前的点击手势需要多长时间才能开始拖动
fromX:起点X坐标
fromY:起点Y坐标
toX:终点X坐标
toY:终点Y坐标
以上都是必要参数。
element:控件ID,可以指定为None,为None时以整个手机屏幕为边界。
示例:
driver.execute_script("mobile:dragFromToForDuration",{"duration":0.5,"element":None,"fromX":0,"fromY":650,"toX":0,"toY":100}
该方法在调用过程中,执行速度快,滑动屏幕距离可根据屏幕进行控制,但是如果滑动中起点坐标在控件上,会触发点击操作。

参考:

https://dpgraham.github.io/appium-docs/writing-and-running/ios-xctest-mobile-gestures/

https://appium.io/docs/en/writing-running-appium/ios/ios-xctest-mobile-gestures/

http://appium.io/docs/en/writing-running-appium/touch-actions/

猜你喜欢

转载自blog.csdn.net/qq_42293590/article/details/89916751