MultiAction是针对多点触控操作的,是TouchAction的一个补充模块 TouchAction用法参考前面的一篇:appium+python自动化33-解锁九宫格(TouchAction)
class MultiAction(object):
def __init__(self, driver, element=None):
self._driver = driver
self._element = element
self._touch_actions = []
def add(self, *touch_actions):
"""添加TouchAction事件
:Args:
- touch_actions - one or more TouchAction objects describing a chain of actions to be performed by one finger
:Usage:
a1 = TouchAction(driver)
a1.press(el1).move_to(el2).release()
a2 = TouchAction(driver)
a2.press(el2).move_to(el1).release()
MultiAction(driver).add(a1, a2)
"""
def perform(self):
"""Perform the actions stored in the object.
:Usage:
a1 = TouchAction(driver)
a1.press(el1).move_to(el2).release()
a2 = TouchAction(driver)
a2.press(el2).move_to(el1).release()
MultiAction(driver).add(a1, a2).perform()
"""
from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.common.multi_action import MultiAction
# el是定位元素的对象
action0 = TouchAction().tap(el)
action1 = TouchAction().tap(el)
MultiAction().add(action0).add(action1).perform()