zoukankan      html  css  js  c++  java
  • Python3+Selenium3自动化测试-(四)

    selenium鼠标事件

    # coding=utf-8
    
    import time
    
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.action_chains import ActionChains
    
    driver = webdriver.Chrome()
    
    driver.get("https://www.baidu.com")
    time.sleep(3)
    
    # 定位元素
    ele_1 = driver.find_element(By.XPATH, '//*[@id="u1"]/a[9]')
    ele_2 = driver.find_element(By.XPATH, '//*[@id="u1"]/a[8]')
    
    # 将鼠标悬停在元素1上3秒后再次悬停到元素2上
    ActionChains(driver).move_to_element(ele_1).perform()
    time.sleep(3)
    ActionChains(driver).move_to_element(ele_2).perform()
    time.sleep(3)
    
    driver.quit()
    # coding=utf-8
    
    import time
    
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.action_chains import ActionChains
    
    driver = webdriver.Chrome()
    
    driver.get("https://www.baidu.com")
    time.sleep(3)
    
    # 定位元素
    ele_1 = driver.find_element(By.XPATH, '//*[@id="u1"]/a[9]')
    ele_2 = driver.find_element(By.XPATH, '//*[@id="u1"]/a[8]')
    
    # 将鼠标悬停在元素1上3秒后再次悬停到元素2上
    ActionChains(driver).move_to_element(ele_1).perform()
    time.sleep(3)
    ActionChains(driver).move_to_element(ele_2).perform()
    time.sleep(3)
    
    driver.quit()
    """
    click(on_element=None) ——单击鼠标左键
    
    click_and_hold(on_element=None) ——点击鼠标左键,不松开
    
    context_click(on_element=None) ——点击鼠标右键
    
    double_click(on_element=None) ——双击鼠标左键
    
    drag_and_drop(source, target) ——拖拽到某个元素然后松开
    
    drag_and_drop_by_offset(source, xoffset, yoffset) ——拖拽到某个坐标然后松开
    
    key_down(value, element=None) ——按下某个键盘上的键
    
    key_up(value, element=None) ——松开某个键
    
    move_by_offset(xoffset, yoffset) ——鼠标从当前位置移动到某个坐标
    
    move_to_element(to_element) ——鼠标移动到某个元素
    
    move_to_element_with_offset(to_element, xoffset, yoffset) ——移动到距某个元素(左上角坐标)多少距离的位置
    
    perform() ——执行链中的所有动作
    
    release(on_element=None) ——在某个元素位置松开鼠标左键
    
    send_keys(*keys_to_send) ——发送某个键到当前焦点的元素
    
    send_keys_to_element(element, *keys_to_send) ——发送某个键到指定元素
    """
    

      

  • 相关阅读:
    nyoj 599-奋斗的小蜗牛 (double ceil(); (temp
    nyoj 596-谁是最好的Coder (greater, less)
    nyoj 517-最小公倍数 (python range(start, end) range(length))
    用深度学习预测专业棋手走法
    阿里AI设计师一秒出图,小撒连连惊呼,真相是...
    想成为数据科学家?先做到这6点吧!
    Kubernetes 弹性伸缩全场景解析 (一)- 概念延伸与组件布局
    机器学习基础:(Python)训练集测试集分割与交叉验证
    Data Lake Analytics + OSS数据文件格式处理大全
    聊聊Flexbox布局中的flex的演算法
  • 原文地址:https://www.cnblogs.com/royfans/p/9906168.html
Copyright © 2011-2022 走看看