python+selenium模拟鼠标操作
from selenium.webdriver.common.action_chains import ActionChains #导入鼠标相关的包 --------------------------------------------------------------------------------------------
submit = driver.find_element_by_id('kw') #首先创建对象
ActionChains(driver).click(submit).perform() #左键
ActionChains(driver).context_click(submit).perform() #右键
ActionChains(driver).double_click(submit).perform() #双击
----------------------------------------------------------------------------------------------------------------------
ActionChains(driver).drag_and_drop_by_offset(submit,10,10).perform() #拖放到指定坐标位置
#target也是创建的一个对象
ActionChains(driver).drag_and_drop(submit,target).perform() #拖放到目标元素位置
--------------------------------------------------------------------------------------------
ActionChains(driver).move_by_offset(10,10).perform() #鼠标在指定坐标悬停
ActionChains(driver).move_to_element(submit).perform() #鼠标在指定元素悬停
ActionChains(driver).move_to_element_with_offset(submit,5,5).perform() #鼠标在指定元素的指定坐标悬停
---------------------------------------------------------------------------------------------------------
ActionChains(driver).click_and_hold(submit).perform() #鼠标左键元素并保持
ActionChains(driver).context_click(submit).perform() #鼠标右键元素并保持
-----------------------------------------------------------------------------------------------
ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform() #ctrl+c 拷贝组合键
================================================================================================
from selenium import webdriver
from selenium.webdriver.common.keys import Keys #导入键盘相关的包
from selenium.webdriver.common.action_chains import ActionChains #导入鼠标相关的包
from time import sleep driver = webdriver.Firefox() # 指定和打开浏览器
driver.get('http://www.baidu.com') #driver.find_element_by_id('kw').send_keys('中国')
#sleep(4) #submit = driver.find_element_by_id('su')
#ActionChains(driver).click(submit).perform() #对搜索按钮 鼠标左点击
#sleep(4) #------------------------------------------------------------------------------------------ #submit = driver.find_element_by_link_text("设置")
#ActionChains(driver).move_to_element(submit).perform() #鼠标悬停在上面
#sleep(5) #driver.find_element_by_class_name("setpref").click() # 打开搜索设置
#sleep(2) #-----------------------------------------------------------------------------------------
location01 = driver.find_element_by_link_text('新闻') # 鼠标拖动事件
sleep(7)
location02 = driver.find_element_by_link_text('更多产品')
ActionChains(driver).drag_and_drop(location01, location02).perform() sleep(8)
driver.close()
=============================================================================================
from selenium import webdriver
from selenium.webdriver.common.keys import Keys #导入键盘相关的包
from selenium.webdriver.common.action_chains import ActionChains #导入鼠标相关的包
from time import sleep driver = webdriver.Firefox() # 指定和打开浏览器
driver.get('http://www.baidu.com') driver.find_element_by_id('kw').send_keys('中国')
sleep(4) driver.find_element_by_id('kw').click() ActionChains(driver).key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).perform() #全选
sleep(4)
ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform() #复制、拷贝
sleep(4)
driver.find_element_by_id('kw').click()
ActionChains(driver).key_down(Keys.CONTROL).send_keys('v').key_up(Keys.CONTROL).perform() #粘贴 sleep(8) driver.close()
python+selenium模拟鼠标操作的更多相关文章
- selenium模拟鼠标操作
Selenium提供了一个类ActionChains来处理模拟鼠标事件,如单击.双击.拖动等. 基本语法: class ActionChains(object): """ ...
- python selenium模拟滑动操作
selenium.webdriver提供了所有WebDriver的实现,目前支持FireFox.phantomjs.Chrome.Ie和Remote quit()方法会退出浏览器,而close()方法 ...
- 模拟鼠标操作(ActionChains)(转 侵删)
在日常的测试中,经常会遇到需要鼠标去操作的一些事情,比如说悬浮菜单.拖动验证码等,这一节我们来学习如何使用webdriver模拟鼠标的操作 首页模拟鼠标的操作要首先引入ActionChains的包 f ...
- Python+Selenium自动化 模拟鼠标操作
Python+Selenium自动化 模拟鼠标操作 在webdriver中,鼠标的一些操作如:双击.右击.悬停.拖动等都被封装在ActionChains类中,我们只用在需要使用的时候,导入这个类就 ...
- 使用Python+Selenium模拟登录QQ空间
使用Python+Selenium模拟登录QQ空间爬QQ空间之类的页面时大多需要进行登录,研究QQ登录规则的话,得分析大量Javascript的加密解密,这绝对能掉好几斤头发.而现在有了seleniu ...
- Java&Selenium 模拟鼠标方法封装
Java&Selenium 模拟鼠标方法封装 package util; import org.openqa.selenium.By; import org.openqa.selenium.W ...
- windows7如何用键盘模拟鼠标操作
windows7如何用键盘模拟鼠标操作 https://jingyan.baidu.com/article/6dad5075104907a123e36e38.html 听语音 37453人看了这个视频 ...
- python+selenium模拟京东登录后台
python+selenium模拟京东登录后台 import json from time import sleep from selenium import webdriver #from sele ...
- python + selenium webdriver 通过python来模拟鼠标、键盘操作,来解决SWFFileUpload调用系统底层弹出框无法定位问题
Webdriver是基于浏览器操作的,当页面上传文件使用的是flash的控件SWFFileUpload调用的时候,调用的是系统底层的文件选择弹出框 这种情况,Webdriver暂时是不支持除页面外的其 ...
随机推荐
- C# List 过滤,排序,删除
taskList_IsManager.Where(p => p.IsManager == "1").ToList(); taskList = taskList.OrderBy ...
- CodeForces-721B-Passwords
链接: https://vjudge.net/problem/CodeForces-721B 题意: Vanya is managed to enter his favourite site Code ...
- CodeForces-598D(BFS,染色)
链接: https://vjudge.net/problem/CodeForces-598D 题意: Igor is in the museum and he wants to see as many ...
- [每日一讲] Python系列:列表与元组
参考文档 https://docs.python.org/zh-cn/3.7/tutorial/introduction.html#lists """ DATA STRU ...
- 约瑟夫环(CVTE、网易2014.3.16笔试题offerP228)
题目:0,1,2,……,n-1这n个数字排成一个圆圈,从数字0开始每次从这个圆圈里删除第m个数字.求出这个圆圈里剩下的最后一个数字. 法一:用环形链表模拟圆圈的经典算法(时间复杂度O(nm),空间复杂 ...
- Python Number(数字) Ⅱ
Python math 模块.cmath 模块 Python 中数学运算常用的函数基本都在 math 模块.cmath 模块中. Python math 模块提供了许多对浮点数的数学运算函数. Pyt ...
- 对前端Jenkins自动化部署的研究
1. 安装 安装 Nginx 1.1去官网下直接下载,解压缩 start nginx就可以使了,常用命令: start nginx # 启动 nginx -s reload # 修改配置后重新加载生效 ...
- python导入包失败ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
最近在看 python,在使用matplotlib进行绘图时,提示:ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplot ...
- BZOJ 5028 小z的加油站
bzoj链接 Time limit 10000 ms Memory limit 262144 kB OS Linux 感想 树上动态gcd的第二题也好了. [x] BZOJ 2257 [JSOI200 ...
- Redis高级命令及特性(安全性)
高级命令 keys * : 返回满足的所有键 ,可以模糊匹配 exists :是否存在指定的key,存在返回1,不存在返回0 exprie:设置某个key的过期时间 ttl:查看剩余时 ...