zoukankan      html  css  js  c++  java
  • 鼠标的操作

    1、鼠标的操作:

    有时候我们要实现,鼠标双击,右击等操作,那么如何实现鼠标的操作呢

    实现的思路:
    需要引入ActionChains类
    然后定位相关元素
    在ActionChains().调用相关鼠标的操作方法

    例如:百度搜索框里面,输入Python,然后双击鼠标,然后在点击右键,在使鼠标悬停在设置的标签上;

    通过F12键盘定位了,百度的搜索框:

     1 from selenium import webdriver
     2 from time import sleep
     3 #这个是操作鼠标的类
     4 from selenium.webdriver.common.action_chains import ActionChains
     5 
     6 driver=webdriver.Chrome()
     7 driver.get("http://www.baidu.com")
     8 sleep(2)
     9 driver.maximize_window()
    10 #在搜索框里输入Python
    11 driver.find_element_by_css_selector("#kw").send_keys("python")
    12 
    13 #执行搜索框里面双击的操作
    14 element=driver.find_element_by_css_selector("#kw")
    15 ActionChains(driver).double_click(element).perform()
    16 sleep(3)
    17 #driver.quit()
    18 
    19 #执行鼠标的右击操作
    20 ActionChains(driver).context_click(element).perform()
    21 sleep(2)
    22 
    23 
    24 #定位百度页面的设置
    25 above=driver.find_element_by_css_selector(".pf")
    26 #当鼠标悬停在一个超链接的地址列表上的时候
    27 
    28 ActionChains(driver).move_to_element(above).perform()
    29 
    30 sleep(3)
    31 driver.quit()

    这就是实现了上述的需求

  • 相关阅读:
    HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树
    字典树 HDU 1075 What Are You Talking About
    字典树 HDU 1251 统计难题
    最小生成树prim算法 POJ2031
    POJ 1287 Networking 最小生成树
    次小生成树 POJ 2728
    最短路N题Tram SPFA
    poj2236 并查集
    POJ 1611并查集
    Number Sequence
  • 原文地址:https://www.cnblogs.com/surewing/p/7865859.html
Copyright © 2011-2022 走看看