zoukankan      html  css  js  c++  java
  • Python+selenium 鼠标三种(双击/右击/悬浮)操作方式(附代码!!)

    思路:

    • 需要引入ActionChains
    • 然后定位相关元素
    • ActionChains().调用相关鼠标操作方法

    具体代码如下:

    # #!/usr/bin/python3
    # -*- coding: utf-8 -*-
    # @Time : 2020/7/29 9:29
    # @Author : Gengwu
    # @FileName: Mouse_Acton.py
    # @Software: PyCharm
    
    from selenium import webdriver
    from time import sleep #时间类
    from selenium.webdriver.common.action_chains import ActionChains #需要引入ActionChains类,里面有鼠标调用的方法
    driver=webdriver.Chrome() #打开chrome浏览器 driver.get('https://www.baidu.com/') #打开百度地址 driver.maximize_window() #窗口最大化 sleep(3) driver.find_element_by_css_selector('#kw').send_keys('python') #定位到搜索框按钮,并输入python #获取搜索框元素对象 element=driver.find_element_by_css_selector('#kw') #存储到变量里面,定位到搜索框 sleep(3) #双击操作 ActionChains(driver).double_click(element).perform() # 在搜索框按钮里面双击,perform执行操作. sleep(2) #右击操作 ActionChains(driver).context_click(element).perform() #在搜索框按钮里面右击,perform执行操作. sleep(2) #鼠标悬停 above=driver.find_element_by_name("tj_settingicon") #通过name找到设置按钮 ActionChains(driver).move_to_element(above).perform() #move_to_element移到设置的元素,avove上面定位到的设置.然后执行操作 sleep(4) driver.quit()#退出浏览器
  • 相关阅读:
    资料网站
    HTML、CSS部分
    面试题三
    面试题二
    面试题一
    上学时的HTML+JS+CSS(小总结)
    01.策略模式-上篇
    【解决方案】HTTP could not register URL http://+:6001/
    【问题与思考】1+"1"=?
    WCF安全3-Transport与Message安全模式
  • 原文地址:https://www.cnblogs.com/gengwulovestudy/p/13398530.html
Copyright © 2011-2022 走看看