appium九宫格解锁错误提示:The coordinates provided to an interactions operation are invalid解决办法

原文地址:http://blog.csdn.net/qqtMJK/article/details/77838814

今天做自动化解锁9宫格,发现swipe不能满足需求,于是用TouchAction去实现手势滑动,这里先给出我写的代码:

TouchAction(self.driver).press(x=299, y=744).wait(100)\  
    .move_to(x=483, y=0).wait(100)\  
    .move_to(x=-483, y=501).wait(100)\  
    .move_to(x=483, y=0).wait(100).release().perform()

 

根据UIAutomatorViewer抓到的坐标,我的坐标滑动需求是(299,744)—>(782,744)—>(299,1245)—>(782,1245)

这个走势也就是一个“Z”字形的解锁路线。

这里给出move_to的代码:

def move_to(self, el=None, x=None, y=None):  
    """Move the pointer from the previous point to the element or point specified 
    """  
    self._add_action('moveTo', self._get_opts(el, x, y))  
  
    return self

然后我执行我的代码之后还是报错:

The coordinates provided to an interactions operation are invalid.

提示说我的坐标无效,但是我确实填写的没有问题。然后我去翻看appium服务的log:

从log看出,前面的坐标操作都是没有问题的,“Z”字可以正常画出来,但是最后touchUp的时候失败了,居然识别

的是一个中间的偏移坐标值做touchUp,正好我这个偏移值还是负数,不在bounds里面,所以提示出错了。

这里先不讨论原因,我改动代码之后就OK了,我贴出改动后的代码:

TouchAction(self.driver).press(x=299, y=744).wait(100)\  
    .move_to(x=483, y=0).wait(100)\  
    .move_to(x=-483, y=501).wait(100)\  
    .move_to(x=483, y=0).wait(100).release().wait(100).perform()

标红的地方就是改动点,我仅仅是在release()后面加了一个wait就保证了touchUp正常执行

就能正常在最后一个点touchUp。

具体原因我不在此详细分析,感兴趣的可以去分析appium底层是怎么执行的

posted @ 2018-02-27 10:50  悠然现南山  阅读(390)  评论(0编辑  收藏  举报