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暂时是不支持除页面外的其 ...
随机推荐
- webpack多页应用
本文主要讲了webpack怎么搭建多页应用,熟悉下webpack的基本用法. 新建文件夹,目录结构如下: 然后 cd webpack-test npm init(根目录下创建了一个pakage.jso ...
- share point 字段类型
Type (as shown on the Create Column page) Field Type Notes MSDN Links Single line of text Type=”Text ...
- win10激活方法 windows 10 最简单的激活方法
1.首先,要用管理员权限打开cmd命令行窗口,可以搜索框中输入“cmd”,在出现的“命令行提示符”,图标上右击“以管理员身份运行”. 2.为了让其它激活工具的密钥清除,先卸载密钥,在命令行输入 ...
- 《SaltStack技术入门与实践》—— 实践案例 <中小型Web架构>3 Memcached配置管理
实践案例 <中小型Web架构>3 Memcached配置管理 本章节参考<SaltStack技术入门与实践>,感谢该书作者: 刘继伟.沈灿.赵舜东 Memcached介绍 Me ...
- Fortran代码生成so库
例: ifort -c -fpic test.f90ifort -shared -o test.so test.o
- java——AtomicInteger 中 incrementAndGet与getAndIncrement 两个方法的区别
https://blog.csdn.net/chenkaibsw/article/details/81031950 源码: getAndIncrement: public final int getA ...
- leaflet 地图容器大小改变时,地图自适应新容器
window.onload = function () { changeDivHeight(); } //当浏览器窗口大小改变时,设置显示内容的高度 window.onresize = functio ...
- python+selenium封装UI自动化框架
seleinum框架 框架的思想: 解决我们测试过程中的问题:大量的重复步骤,用自动化来实现 1)配置和程序的分离 2)测试数据和程序的分离 3)不懂编程的人员可以方便使用:使用的 ...
- JPA学习(三、JPA_API)
框架学习之JPA(三) JPA是Java Persistence API的简称,中文名Java持久层API,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中 ...
- C++ - 操作运算符
一.操作运算符 操作运算符:在C++中,编译器有能力将数据.对象和操作符共同组成表达式,解释为对全局或成员函数的调用 该全局或成员函数被称为操作符函数,程序员可以通过重定义函数操作符函数,来达到自己想 ...