关于appium+python里self.driver.tap([(x,y)])无效的原因

关于appium+python里self.driver.tap([(x,y)])无效的原因


今天写自动化,找不到元素点位,只能通过坐标去点击,于是使用tap去实现。

但是运行到tap的时候出错,提示找不到元素。去看了源码,发现并没有写错格式。

这里给个源码:

def tap(self, positions, duration=None):
    """Taps on an particular place with up to five fingers, holding for a
    certain time

    :Args:
     - positions - an array of tuples representing the x/y coordinates of
     the fingers to tap. Length can be up to five.
     - duration - (optional) length of time to tap, in ms

    :Usage:
        driver.tap([(100, 20), (100, 60), (100, 100)], 500)
    """
    if len(positions) == 1:
        action = TouchAction(self)
        x = positions[0][0]
        y = positions[0][1]
        if duration:
            action.long_press(x=x, y=y, duration=duration).release()
        else:
            action.tap(x=x, y=y)
        action.perform()
    else:
        ma = MultiAction(self)
        for position in positions:
            x = position[0]
            y = position[1]
            action = TouchAction(self)
            if duration:
                action.long_press(x=x, y=y, duration=duration).release()
            else:
                action.press(x=x, y=y).release()
            ma.add(action)

        ma.perform()
    return self


最后觉得可能是页面还没跳转就实现了tap,所有加了一个WebDriverWait去判断元素存在,最后成功实现。

因为之前一直用的click(),click是识别元素才进行点击的,然而坐标信息是一直存在的,所以tap会直接运行,前面务必加上延时或者判断!!!


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值