1、移动鼠标的操作
1.1 将鼠标移动到
actions = ActionChains(self.driver)
actions.move_to(element, 10, 10)
actions.perform()
如果未指定任何元素,则移动相对于当前鼠标光标。 如果提供了一个元素但没有偏移,则鼠标将移动到元素的中心。 如果元素不可见,它将滚动到视图中。
1.2 在当前鼠标坐标处单击任意鼠标按钮
actions = ActionChains(self.driver)
actions.move_to_element(element)
actions.click()
actions.perform()
1.3 双击当前鼠标坐标(由 moveto 设置)
actions = ActionChains(self.driver)
actions.move_to_element(element)
actions.double_click()
actions.perform()
1.4 在当前鼠标坐标处单击并按住鼠标左键
actions = ActionChains(self.driver)
actions.move_to_element(element)
actions.click_and_hold()
actions.perform()
1.5 释放之前按住的鼠标按钮
actions = ActionChains(self.driver)
actions.move_to_element(element)
actions.click_and_hold()
actions.move_to_element(element, 10, 10)
action.release()
actions.perform()
2、触碰屏幕的操作
2.1 手指在屏幕上单击
from appium.webdriver.common.touch_action import TouchAction
actions = TouchAction(driver)
actions.tap(element)
actions.perform()
2.2 手指在触摸屏上双击
from appium.webdriver.common.touch_action import TouchAction
actions = TouchAction(driver)
actions.double_tap(element)
actions.perform()
2.3 手指在屏幕上移动
from appium.webdriver.common.touch_action import TouchAction
actions = TouchAction(driver)
actions.tap_and_hold(element)
actions.move_to(element, 50, 50)
actions.perform()
2.4 手指在屏幕上向下
from appium.webdriver.common.touch_action import TouchAction
actions = TouchAction(driver)
actions.tap_and_hold(element)
actions.move(50, 50)
actions.perform()
2.5 手指在屏幕上 release
from appium.webdriver.common.touch_action import TouchAction
actions = TouchAction(driver)
actions.tap_and_hold(20, 20)
actions.release(50, 50)
actions.perform()
2.6 手指运动事件长按触摸屏
from appium.webdriver.common.touch_action import TouchAction
actions = TouchAction(driver)
actions.long_press(element)
actions.perform()
2.7 手指在触摸屏上滚动
from appium.webdriver.common.touch_action import TouchAction
actions = TouchAction(driver)
actions.scroll_from_element(element, 10, 100)
actions.scroll(10, 100)
actions.perform()
2.8 手指在触摸屏上轻弹
from appium.webdriver.common.touch_action import TouchAction
actions = TouchAction(driver)
actions.flick_element(element, 1, 10, 10)
actions.perform()
2.9 执行多点触控动作序列
from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.common.multi_action import MultiAction
a1 = TouchAction()
a1.press(10, 20)
a1.move_to(10, 200)
a1.release()
a2 = TouchAction()
a2.press(10, 10)
a2.move_to(10, 100)
a2.release()
ma = MultiAction(self.driver)
ma.add(a1, a2)
ma.perform()
2.10 执行触摸动作序列
from appium.webdriver.common.touch_action import TouchAction
// ...
actions = TouchAction(driver)
actions.tap_and_hold(20, 20)
actions.move_to(10, 100)
actions.release()
actions.perform()
3 W3C actions
行一系列或多个键盘和指针(触摸、鼠标、触控笔)操作链
element = self.driver.find_element_by_accessibility_id("elId")
actions = ActionChains(self.driver)
actions.move_to_element(element)
actions.click(hidden_submenu)
actions.perform()
|