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 ...
随机推荐
- math random模块
math --- 数学函数 该模块提供了对C标准定义的数学函数的访问,返回值除非有明确说明,否则所有返回值均为浮点数 math.ceil(x) 返回 x 的上限,即大于或者等于 x 的最小整数. 如果 ...
- Smith Numbers(分解质因数)
Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14173 Accepted: 4838 De ...
- windows内核编程基础知识
/* 1.基本的驱动数据结构 //驱动对象结构体 typedef struct _DRIVER_OBJECT { CSHORT Type; //结构类型 CSHORT Size; //结构大小 PDE ...
- Dalvik模式下在Android so库文件.init段、.init_array段构造函数上下断点
本文博客地址:http://blog.csdn.net/qq1084283172/article/details/78244766 在前面的博客<在Android so文件的.init..ini ...
- CVE-2013-3346:十全九美的 Adobe Reader ToolButton UAF 漏洞
0x01 "Epic Turla" 网络间谍行动 在 2014 年 8 月,被誉为 "世界十大最危险的网络攻击行动" 之一的 "Epic Turla& ...
- JSON对象与字符串的互换——JSON.parse()和JSON.stringify()
parse用于从一个字符串中解析出json对象,如 var str = '{"name":"huangxiaojian","age":&qu ...
- android之布局优化
android中提供了<include />.<merge />.<ViewStub />三种优化布局. 1.<include /> <inclu ...
- keep-alive与生命周期函数
理解keep-alive keep-alive是Vue内置的一个组件,可以使被包含的组件保留状态,或避免重新渲染 router-view也是一个组件,如果直接被keep-alive包在里面,所有路径匹 ...
- Charles的功能(web)
# 验证是否可以获取web端的https接口 1. 打开Charles 2.打开游览器输入数据 3. 查看Charles 4.从上图所看,能获取htpps的包数据,即可对web端进行抓包 4.char ...
- C++ primer plus读书笔记——第6章 分支语句和逻辑运算符
第6章 分支语句和逻辑运算符 1. 逻辑运算符的优先级比关系运算符的优先级低. 2. &&的优先级高于||. 3. cctype中的函数P179. 4. switch(integer- ...