Python+Selenium - 鼠标操作
鼠标操作类: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()
Python+Selenium - 鼠标操作的更多相关文章
- 【python】鼠标操作
[python]鼠标操作 推荐地址:http://www.cnblogs.com/fnng/p/3288444.html --------------------------------------- ...
- python selenium鼠标键盘操作(ActionChains)
用selenium做自动化,有时候会遇到需要模拟鼠标操作才能进行的情况,比如单击.双击.点击鼠标右键.拖拽等等.而selenium给我们提供了一个类来处理这类事件--ActionChains sele ...
- python+selenium 鼠标事件操作
一.前言 除了可以使用 click( ) 来模拟鼠标的单击操作,现在Web产品中还提供了更丰富的鼠标交互方式,例如鼠标右键.双击.悬停.拖动等功能,在WebDriver中,将这些关于鼠标操作的方法都封 ...
- python selenium --鼠标事件
转自:http://www.cnblogs.com/fnng/p/3288444.html 本节重点: ActionChains 类 context_click() 右击 double_click( ...
- Python+selenium鼠标、键盘事件
鼠标操作 现在的Web产品提供了丰富的鼠标交互方式,例如鼠标右击.双击.悬停.甚至是鼠标拖动等功能,在Webdriver中,将这些关于鼠标操作的方法封装在ActionChains类提供. 1.鼠标右击 ...
- selenium鼠标操作
#-*- coding:utf-8 -*- import time from selenium import webdriver from selenium.webdriver.common.acti ...
- python selenium 相关操作
selenium : 是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE(7, 8, 9, 10, 11),Mozilla Fi ...
- python selenium鼠标滑动操作
先安装pyautogui: pip install pyautogui #coding=utf-8 import pyautogui from selenium import webdriver fr ...
- 9 Python+Selenium鼠标事件
[环境信息] python3.6+Selenium3.0.2+Firefox50.0+win7 [ActionChains类鼠标事件的常用方法] 1.右击:context_click() 2.双击:d ...
随机推荐
- VsCode调试vue项目
VsCode调试vue项目 VsCode如何调试vue项目,VsCode需要安装插件以及配置launch.json文件. 找到"扩展"或者按快捷键"Ctrl+Shift+ ...
- 【Java】 Java中的浅拷贝和深拷贝
先抛出结论: 浅拷贝是引用拷贝,A对象拷贝B以后,A对象和B对象指向同一块内存地址,改变A对象的属性值会触发B对象属性的改变,有安全风险 深拷贝是对象拷贝,A对象拷贝B以后,A对象和B对象指向不同的额 ...
- system , DOS 命令
其实C语言也可以控制电脑关机什么的啊,以前竟然无知的连这个都不知道.悲哀啊.让各路大牛尽情嘲笑啊.. #include<stdio.h> #include<stdlib.h> ...
- LeetCode---42. 接雨水 (hard)
题目:42. 接雨水 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水. 示例: 输入:height = [0,1,0,2,1,0,1,3,2,1,2, ...
- Spring Boot集成sharding-jdbc实现分库分表
一.水平分割 1.水平分库 1).概念:以字段为依据,按照一定策略,将一个库中的数据拆分到多个库中.2).结果每个库的结构都一样:数据都不一样:所有库的并集是全量数据: 2.水平分表 1).概念以字段 ...
- layui中的分页laypage
1.html部分 <div id="test1"></div> 2.js部分: <script src="/static/build/lay ...
- 【Linux】在centos中使用命令安装redis
1.前提centos能够上网 测试方式输入命令,有数据返回即可.如果则先配置centos网络连接. ping www.baidu.com 2.安装gcc 输入命令进行安装 yum install gc ...
- 电脑提示无法装入/加载SolidWorks DLL文件:sldshellutils如何解决
电脑提示无法装入/加载SolidWorks DLL文件:sldshellutils如何解决 参考资料:http://www.xitongcheng.com/jiaocheng/dnrj_article ...
- 2020中国大学生程序设计竞赛(CCPC) - 网络选拔赛总结
1003 Express Mail Taking 题意:有n个柜子(编号1-n),m封信,k号位置有钥匙,现在需要取信封,并且每取一次信封都要从k号位置进行领取一次钥匙,再去有信封的位置领取信封,问最 ...
- linux跨文件复制粘贴
跨文件是这样的: 复制a.txt的第20行至第30行到b.txt中vi a.txt:2010yy:e b.txtp