action=TouchAction(self.driver)创建对象,注意要以当前的驱动作为参数,可以参照源码:
class TouchAction(object):
def __init__(self, driver=None):
self._driver = driver
self._actions = []
def tap(self, element=None, x=None, y=None, count=1):
"""Perform a tap action on the element
源码中的driver默认是空的,所以自己一定要给它赋值,否则编译不会报错,但是运行报错。
然后使用点击方法tap,参照源码:
def tap(self, element=None, x=None, y=None, count=1):
"""Perform a tap action on the element
:Args:
- element - the element to tap
- x - (optional) x coordinate to tap, relative to the top left corner of the element.
- y - (optional) y coordinate. If y is used, x must also be set, and vice versa
:Usage:
"""
从源码可以看到,从第一个参数是元素,这个元素的左上角开始,(x,y)范围内可以点击,count不用写,有默认值1。
而这个x,y的获取,我们也可以参照自定义view的size,具体可以查看断点的时候元素的大小,如图:
最后别忘记了perform,所以代码可以这样写: