• selenium屏幕操作事件TouchActions


    说明:本篇博客基于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()
    

    更多技术文章

  • 相关阅读:
    C/C++图书信息管理系统水电管理信息系统
    加密狗 - 圣天诺
    【杨氏矩阵】
    PHP实现微信支付及退款流程实例
    震惊 !!!DOM还能这么用,让我们跟随小编一起去看看吧 !
    防火防盗防CDN流量盗刷
    用例图包含关系、扩展关系、泛化关系解析(最全总结,非常详细)
    电脑配置PC2022年版(4000元左右)详细配置表——(专业数据)
    JSP合同信息管理系统
    MySQL的varchar存储原理:InnoDB记录存储结构
  • 原文地址:https://blog.csdn.net/Tester_muller/article/details/127070347