鼠标操作类:action_chains模块的ActionChains类

使用组成:操作 + 执行(perform())

导入代码

from selenium.webdriver.common.action_chains import ActionChains

查看代码常用操作有:

click(self, on_element=None)
click_and_hold(self, on_element=None)  #Holds down the left mouse button on an element.
context_click(self, on_element=None)   #Performs a context-click (right click) on an element.
double_click(self, on_element=None)   
drag_and_drop(self, source, target)   #Holds down the left mouse button on the source element, then moves to the target element and releases the mouse button.
move_to_element(self, to_element)   #Moving the mouse to the middle of an element.
release(self, on_element=None)   #Releasing a held mouse button on an element.

perform() #调用这个函数执行鼠标操作

示例:

from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.baidu.com/")
sleep(1)
#找到元素
loc = (By.ID,"s-usersetting-top")
ele = driver.find_element(*loc)
#对元素进行鼠标操作
#实例化ActionChains类
ac = ActionChains(driver)
# 把鼠标悬浮在这个元素
ac.move_to_element(ele)
# ac.move_to_element(ele).click(ele) #鼠标悬浮并点击。可把两个动作拆开写
#执行操作。鼠标操作最后要有一个perform(),执行perform()后面还有鼠标操作代码时,需要再调用一次perform()
ac.perform()
sleep(3)
driver.quit()

最新文章

  1. 【Go入门教程3】流程(if、goto、for、switch)和函数(多个返回值、变参、传值与传指针、defer、函数作为值/类型、Panic和Recover、main函数和init函数、import)
  2. JAVA jdbc获取数据库连接
  3. JavaScript DOM编程艺术学习笔记(一)
  4. jQuery插件Skippr实现焦点图
  5. 【javascript】html5中使用canvas编写头像上传截取功能
  6. 生产环境服务CPU高问题分析
  7. 【BZOJ 1491】 [NOI2007]社交网络
  8. c#基础知识对比(面向对象)
  9. 百度文本编辑器 Ueditor for net 使用七牛存储附件的实现
  10. 使用JS截取字符串函数详解
  11. Android应用程序框架层和系统运行库层日志系统源代码分析
  12. 一个很好的通用 excel 导出工具类
  13. SQLyog快捷键汇总
  14. Win10更新
  15. 读了这篇文章,你将变身web分析大师
  16. sqlserver打开对象资源管理器管理的帮助文档的快捷键
  17. Jquery——hover与toggle
  18. IRing项目开发
  19. django数据库基本操作-增删改查(tip)-基本
  20. TOSCA自动化测试工具--怎么写自动化用例

热门文章

  1. hdu3793 判断对称(水题)
  2. Social engineering tookit 钓鱼网站
  3. Tomcat反序列化漏洞(CVE-2016-8735)
  4. javaScript的成长之路【何为函数,面向对象又是啥!!!】
  5. python三元(三目)运算
  6. JVM什么叫安全检测点
  7. (10)MySQL进阶篇SQL优化(InnoDB锁-间隙锁)
  8. Redis数据结构—跳跃表
  9. BD-rate的计算
  10. [Java] 开课吧--JVM