zoukankan      html  css  js  c++  java
  • web自动化之鼠标事件

    鼠标操作
    from selenium.webdriver.common.action_chains import ActionChains
    通过ActionChains 类来完成鼠标操作
    主要操作流程:
    1.存储鼠标操作
    2.perform()执行鼠标操作

    常见的鼠标操作
    double_click 双击
    context_clik 右键操作
    drag_and_drop 拖拽操作。 左键按住拖动某一个元素到另外一个元素,然后释放按键
    move_to_element() 鼠标悬停

    from selenium import webdriver
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as Ec
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.action_chains import ActionChains  # 鼠标操作的类
    
    driver = webdriver.Chrome()
    
    driver.get("https://www.baidu.com/")
    # 窗口最大化
    driver.maximize_window()
    # 等待元素出现
    WebDriverWait(driver,20).until(Ec.visibility_of_element_located((By.XPATH,'//div[@id="u1"]//a[text()="设置"]')))
    # 鼠标悬浮到设置按钮上
    web = driver.find_element_by_xpath('//div[@id="u1"]//a[text()="设置"]')
    ac = ActionChains(driver)
    ac.move_to_element(web).perform()
    #  点击操作
    driver.find_element_by_xpath('//div[@id="u1"]//a[text()="设置"]').click()
    # 等待元素出现
    WebDriverWait(driver,20).until(Ec.visibility_of_element_located((By.XPATH,'//a[text()="高级搜索"]')))
    # 点击高级搜索
    driver.find_element_by_xpath('//a[text()="高级搜索"]').click()
  • 相关阅读:
    vuejs中使用echart图表
    锚点链接
    如何动态修改网页的标题(title)?
    如何为图片添加热点链接?(map + area)
    cookie
    如何为你的网站添加标志性的图标(头像)呢?
    图片拖拽上传至服务器
    js定时器之setTimeout的使用
    input[type=file]中使用ajaxSubmit来图片上传
    input[type=file]样式更改以及图片上传预览
  • 原文地址:https://www.cnblogs.com/666666pingzi/p/10555983.html
Copyright © 2011-2022 走看看