Appium+Python Flick longpress press区别(Android)

在使用Appium的Python client端的写Android脚本时,发现使用flick方法输出滑动不好控制,明明是偏移量100px但是有时候滑动很快直接到底部,有时又是100px的距离。所以这样导致我们在写滑动时候很难控制滑动精确位置。经测试发现是Appium Python client端一个Bug导致。 我们通过将flick方法中press修改为longpress解决这个问题

Appium Python client API

def flick(self, start_x, start_y, end_x, end_y):
"""
  Flick from one point to another point.

: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

:Usage:
driver.flick(100, 100, 100, 400)
"""
action = TouchAction(self)
    action \
        .press(x=start_x, y=start_y) \
        .move_to(x=end_x, y=end_y) \
        .release()
    action.perform()
    return self

上文中使用的press
moveto 中 endx,endy 是相对startx,start_y的偏移量 并存在随机滑动加速度或缓冲滑动
TouchAction(driver) .press({x: 532, y: 1278}) .moveTo({x: 12: y: -371}) .release()

修改后 Appium Python client API

def flick(self, start_x, start_y, end_x, end_y):
  """
    Flick from one point to another point.

    :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

    :Usage:
    driver.flick(100, 100, 100, 400)
  """
    action = TouchAction(self)
        action \
            .long_press(x=start_x, y=start_y) \
            .move_to(x=end_x, y=end_y) \
            .release()
        action.perform()
        return self

上文使用longpress moveto 中 endx,endy 是绝对值 (startx,endx) TouchAction(driver) .press({x: 532, y: 1278}) .moveTo({x: 532: y: 1000}) .release()
其中如有错误,欢迎指正 讨论QQ群:658703911

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容