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暂时是不支持除页面外的其 ...
随机推荐
- jpa 自定义sql 删除方法注意点
1.jpa自带的delete()方法可以成功删除对象 delete(id),或者delete(entity) 2.自定义删除方法注意点 参考:https://www.jianshu.com/p/9d5 ...
- json与string与map的理解
json是一种特殊格式的string字符串,也就是json也是string类型,只是这种string是有格式的,那么他的格式就是类似map的格式[key:value] 举例子: Map map = r ...
- 聚合函数 Aggregate Function
聚合函数是用来统计每个分组的统计信息,它们要跟 group by 一起使用,用来将每个分组所有数据 聚合 成一条统计数据. 包括 max/min/count/avg/sum 等. -- 按照部门进行分 ...
- Python之常用模二(时间、序列号等等)
一.time模块 表示时间的三种方式: 时间戳:数字(计算机能认识的) 时间字符串:t='2012-12-12' 结构化时间:time.struct_time(tm_year=2017, tm_mon ...
- centos6.5下修改系统的roo用户/非root用户的密码
1.修改系统root用户的密码 [........~]# passwd然后输入新密码,若提示密码太简单,无需理会,直接敲回车: 然后再次输入新密码,即可修改成功. 2.修改系统非root用户的密码:e ...
- linux安装配置Redis,Swoole扩展
我是使用的是lnmp环境(php5.6.3) 一.安装redis数据库(参考w3c手册) 下载地址:http://redis.io/download 本教程使用的最新文档版本为 2.8.17,下载并安 ...
- SQLite为何要用C语言来开发?
SQLite 选择 C 语言的理由是?为什么不选择 Go 或者 Rust? C 语言是最好的 SQLite 在 2000 年 5 月 29 日发布,并一直使用 C 语言实现.C 语言一直是实现 SQL ...
- java大文件上传
上次遇到这样一个问题,客户上传高清视频(1G以上)的时候上传失败. 一开始以为是session过期或者文件大小受系统限制,导致的错误.查看了系统的配置文件没有看到文件大小限制,web.xml中sees ...
- JavaScript的事件队列(Event Queue)---宏任务和微任务
前言 在写代码的时候经常思考一个问题,到底是那个函数先执行,本身JavaScript是一门单线程的语言,意思就是按照顺序执行.但是加入一些setTimeout和promise的函数来又实现了异步操作, ...
- python学习之路(24)
访问限制 在Class内部,可以有属性和方法,而外部代码可以通过直接调用实例变量的方法来操作数据,这样,就隐藏了内部的复杂逻辑. 但是,从前面Student类的定义来看,外部代码还是可以自由地修改一个 ...