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 ...
随机推荐
- java面试一日一题:mysql中的自增主键
问题:请讲下mysql中的自增主键 分析:该问题主要考察对mysql中自增主键的掌握,使用场景及如何设置 回答要点: 主要从以下几点去考虑 1.什么自增主键 2.使用场景是什么: 3.innodb_a ...
- 谈谈SSRF漏洞挖掘
最近看了很多ssrf漏洞挖掘技巧和自己以往挖掘ssrf漏洞的一些技巧和经验,简单的总结下: 之前自己总结的: ssrf=服务器端请求伪造 基于服务器攻击 url链接 -->内网漫游/内网服务探测 ...
- Scrum Meeting 目录 && alpha 第一次Scrum Meeting博客
是兄弟就来摸鱼小组 Scrum Meeting 博客汇总 一.Alpha阶段 标号 标题 1 [alpha]第一次Scrum Meeting(见本文) 二.Beta阶段 会议安排 时间 4月23日8时 ...
- 077 Kuchiguse
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- 858. Mirror Reflection
There is a special square room with mirrors on each of the four walls. Except for the southwest cor ...
- 2sat建边总结
2sat的基础建边 AND = 1 : ~x -> x ,~y -> y (两个数必须全为1) AND = 0 : y -> ~x ,x -> ~y (两个数至少有一个为 ...
- PAT 乙级 -- 1011 -- A+B和C
问题简述 给定区间[-231, 231]内的3个整数A.B和C,请判断A+B是否大于C. 输入格式: 输入第1行给出正整数T(<=10),是测试用例的个数.随后给出T组测试用例,每组占一行,顺序 ...
- DVWA之Brute Force
DVWA简介 DVWA(Damn Vulnerable Web Application)是一个用来进行安全脆弱性鉴定的PHP/MySQL Web应用,旨在为安全专业人员测试自己的专业技能和工具提供合法 ...
- Google Chrome飞天小恐龙
输入网址 chrome://dino/ ,F12->console,上代码 满分 Runner.instance_.setSpeed(99999); 不死护体 window.tempGameOv ...
- 15 个让新手爱不释手的 Python 高级库
为什么我喜欢 Python ? 对于初学者来说,这是一种简单易学的编程语言:另一个原因:大量开箱即用的第三方库,正是 23 万个由用户提供的软件包使得 Python 真正强大和流行 在本文中,我挑选了 ...