前言
MultiAction是針對多點觸控操作的,是TouchAction的一個補充模塊
TouchAction用法參考前面的一篇:appium+python自動化33-TouchAction
多點觸控
- 多點觸摸對象是觸摸動作的集合。
- 多點觸控手勢只有兩種方法,即添加和執行。
- add用於添加另一個觸摸操作到多點觸摸。
- 當perform執行被調用時,添加到多點觸摸的所有觸摸動作都被發送到AppII,並執行,就像它們同時發生一樣。appium首先執行所有觸摸動作的第一個事件,然后執行第二個,等等。
MultiAction源碼
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()