Appium笔记4--滑动屏幕操作及UIAutomator介绍

appium提供的滑动屏幕方法

# convenience method added to Appium (NOT Selenium 3)
def swipe(self, start_x, start_y, end_x, end_y, duration=None):
   
"""Swipe from one point to another point, for an optional duration.

    :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
     - duration - (optional) time to take the swipe, in ms.

    :Usage:
        driver.swipe(100, 100, 100, 400)
    """

用法:driver.swipe(200, 500,1000, 500,  duration=500)

参数就是起点和终点x/y坐标

duration是滑动从起点到终点坐标所耗费的时间,单位是毫秒。

注意这个时间非常重要。正常速度滑动和快速滑动的效果是不一样的

 

这样用swipe同样存在的问题就是,兼容性不行。

如果换了屏幕,可能会有问题,比如有的屏幕是分辨率更低的,没有1000y坐标。就出问题了。

 

可以根据元素宽度和左上角坐标来计算出相对坐标

方法是先获:

ele = driver.find_element_by_id('com.huawei.appmarket:id/commodityLL')
location=ele.location#左上角坐标
size=ele.size#元素的高度和宽度

#计算起始点坐标
start_x=location['x']+int(size['width'])*0.2
start_y=location['y']+int(size['height'])*0.5
end_x=location['x']+int(size['width'])*0.8
end_y=

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值