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暂时是不支持除页面外的其 ...
随机推荐
- 利用urllib.urlopen向有道翻译发送数据获得翻译结果
from urllib import request,parseimport requests, sys,ssl,json ssl._create_default_https_context = ss ...
- 2018 ACM-ICPC 区域赛(青岛站)题解整理
题目链接 C - Flippy Sequence(组合数学+分类讨论) 两区间异或一下,分段考虑,如果全为0则任选两相同区间,答案为$C_{n+1}^{2}=\frac{n(n+1)}{2}$,只有一 ...
- chrome 开发者工具 - local overrides
使用chrome 作为本地网络服务 chrome 65+ 新功能, 使用我们自己的本地资源覆盖网页所使用的资源,可以使用本地css文件覆盖网页的css文件,修改样式. 类似的,使用DevTools的工 ...
- AI应该享有与动物一样的权利吗?
全世界的大学都在进行人工智能(AI)的重大研究,艾伦研究所(Allen Institute)等组织以及Google和Facebook等高科技公司.可能的结果是,我们很快将拥有与小鼠或狗一样高的认知能力 ...
- MongoDB实现增删查方法
1.添加信息 public void addInfo(Infomation infomation) { try{ // TODO Auto-generated method stub //连接Mong ...
- C++ std::vector 总结笔记
Initialization #include<iostream> #include<vector> using namespace std; int main() { vec ...
- SQL复杂筛选
SELECT A.MATERIALID,A.MATERIALNAME,ISNULL(A.COMPIDSEQ,'') COMPIDSEQ,ISNULL(A.SUPPLYID,'') SUPPLYID,S ...
- php+html5实现无刷新上传,大文件分片上传,断点续传
核心原理: 该项目核心就是文件分块上传.前后端要高度配合,需要双方约定好一些数据,才能完成大文件分块,我们在项目中要重点解决的以下问题. * 如何分片: * 如何合成一个文件: * 中断了从哪个分片开 ...
- [Usaco2010 Dec]Treasure Chest 藏宝箱
题目链接:点这里 Solution: 刚开始以为是博弈论,然而不是... 首先考虑n方dp,设f(l,r)为只有\(l\)到\(r\)区间的钱的先手最大获利 那么我们可以得到式子f(l,r)=sum( ...
- 【gym102394A】Artful Paintings(差分约束系统,二分)
题意:给定一个长为n的序列,每个位置可以选择取或不取,要求构造方案使得: 1.对于前M1个约束,区间[L,R]内取的数量必须严格不少于K 2.对于后M2个约束,区间[L,R]外取的数量必须严格不少于K ...