python3 uiautomator2 頁面滾動、滑動的相關操作
一、滾動操作:scroll
1、含義理解:滾動頁面,與坐標無關系
2、源碼示例:
3、實際代碼演示:
# 垂直滾動到頁面頂部/橫向滾動到最左側 d(scrollable=True).scroll.toBeginning() d(scrollable=True).scroll.horiz.toBeginning() # 垂直滾動到頁面最底部/橫向滾動到最右側 d(scrollable=True).scroll.toEnd() d(scrollable=True).scroll.horiz.toEnd() # 垂直向后滾動到指定位置/橫向向右滾動到指定位置 d(scrollable=True).scroll.to(description="指定位置") d(scrollable=True).scroll.horiz.to(description="指定位置") # 垂直向前滾動(橫向同理) d(scrollable=True).scroll.forward() # 垂直向前滾動到指定位置(橫向同理) d(scrollable=True).scroll.forward.to(description="指定位置")
4、注意事項:其他頁面滾動的情況請看源碼示例,可以隨意組合,一般情況下都能滾動到自己想要的頁面位置;如果scroll不能滾動到自己想要的位置,請使用swipe方法,如下所示
二、滑動操作:swipe
1、含義理解:從A點滑動到B點,可以理解為滑動屏幕
2、源碼示例:
3、實際代碼演示:
# 從sx,sy坐標滑動至ex,ey坐標 d.swipe(sx, sy, ex, ey)
三、拖拽操作:drag
1、含義理解:把A拖拽到B的位置,可以理解為拖拽按鈕,與swipe類似
2、源碼示例:
3、實際代碼演示:
# 從sx,sy坐標拖拽至ex,ey坐標 d.drag(sx, sy, ex, ey)
來源:https://www.jianshu.com/p/bb4435303214