软件测试|selenium屏幕操作事件TouchActions
【摘要】 说明:本篇博客基于selenium 4.1.0 TouchActions说明ActionChains都是selenium的一个模块,提供模拟屏幕操作的功能 TouchActions使用说明使用方法与ActionChains一致:# 步骤1:实例化一个TouchActions动作容器actions = TouchActions(driver)# 步骤2:往动作容器中依次添加动作actions....
说明:本篇博客基于selenium 4.1.0
TouchActions说明
ActionChains都是selenium的一个模块,提供模拟屏幕操作的功能
TouchActions使用说明
使用方法与ActionChains一致:
# 步骤1:实例化一个TouchActions动作容器
actions = TouchActions(driver)
# 步骤2:往动作容器中依次添加动作
actions.tap(ele_click) # 调用的动作都会添加到动作容器中
actions.double_tap(ele_drag).scroll(0, 1000) # 链式添加动作。每个动作返回值为容器对象,因此支持链式连续添加
# 步骤3:执行动作
actions.perform()
TouchActions
import time
from selenium import webdriver
from selenium.webdriver import TouchActions
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.implicitly_wait(5)
driver.get('https://www.baidu.com/')
actions = TouchActions(driver)
ele_input = driver.find_element(By.ID, "kw")
location = ele_input.location
'''
ActionChains格式,使用方法与ActionChains一致:
1. 实例化一个TouchActions动作容器
actions = TouchActions(driver)
2. 往动作容器添加动作
2.1 直接添加
actions.tap(ele_click) # 调用的动作都会添加到动作容器中
actions.double_tap(ele_drag).scroll(0, 1000) # 链式添加动作。每个动作返回值为容器对象,因此支持链式连续添加
3. 执行动作
actions.perform()
'''
# 鼠标点击
actions.tap(ele_input) # 单击元素
actions.double_tap(ele_input) # 双击元素
actions.long_press(ele_input) # 长按元素
# 鼠标滚动
x, y = 30, 50
actions.scroll(x, y) # 滚动,向下向右(x, y)距离
actions.scroll_from_element(ele_input, x, y) # 滚动,以元素为起点向下向右(x, y)距离
# 鼠标移动
x, y = 0, 1000
actions.move(x, y) # 鼠标移动到坐标(x,y)
# 释放鼠标
actions.release(x, y) # 鼠标移动坐标(x,y),并释放鼠标
# 滑动
xspeed, yspeed = 30, 50
actions.flick(xspeed, yspeed) # 滑动,向下向右以(xspeed, yspeed)速度滑动
xoffset, yoffset, speed = 30, 50, 20
actions.flick_element(ele_input, xoffset, yoffset, speed) # 在元素处滑动,向下向右以speed的速度滑动(xoffset, yoffset)距离
# 拖动
x, y = 30, 50
actions.tap_and_hold(x, y) # 点住,在坐标(x, y)处
# 容器相关
actions.perform() # 按顺序开始执行动作
time.sleep(5)
driver.quit()
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)