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}
該方法在調用過程中,執行速度快,滑動屏幕距離可根據屏幕進行控制,但是如果滑動中起點座標在控件上,會觸發點擊操作。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章