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模拟鼠标操作的更多相关文章

  1. selenium模拟鼠标操作

    Selenium提供了一个类ActionChains来处理模拟鼠标事件,如单击.双击.拖动等. 基本语法: class ActionChains(object): """ ...

  2. python selenium模拟滑动操作

    selenium.webdriver提供了所有WebDriver的实现,目前支持FireFox.phantomjs.Chrome.Ie和Remote quit()方法会退出浏览器,而close()方法 ...

  3. 模拟鼠标操作(ActionChains)(转 侵删)

    在日常的测试中,经常会遇到需要鼠标去操作的一些事情,比如说悬浮菜单.拖动验证码等,这一节我们来学习如何使用webdriver模拟鼠标的操作 首页模拟鼠标的操作要首先引入ActionChains的包 f ...

  4. Python+Selenium自动化 模拟鼠标操作

    Python+Selenium自动化 模拟鼠标操作   在webdriver中,鼠标的一些操作如:双击.右击.悬停.拖动等都被封装在ActionChains类中,我们只用在需要使用的时候,导入这个类就 ...

  5. 使用Python+Selenium模拟登录QQ空间

    使用Python+Selenium模拟登录QQ空间爬QQ空间之类的页面时大多需要进行登录,研究QQ登录规则的话,得分析大量Javascript的加密解密,这绝对能掉好几斤头发.而现在有了seleniu ...

  6. Java&Selenium 模拟鼠标方法封装

    Java&Selenium 模拟鼠标方法封装 package util; import org.openqa.selenium.By; import org.openqa.selenium.W ...

  7. windows7如何用键盘模拟鼠标操作

    windows7如何用键盘模拟鼠标操作 https://jingyan.baidu.com/article/6dad5075104907a123e36e38.html 听语音 37453人看了这个视频 ...

  8. python+selenium模拟京东登录后台

    python+selenium模拟京东登录后台 import json from time import sleep from selenium import webdriver #from sele ...

  9. python + selenium webdriver 通过python来模拟鼠标、键盘操作,来解决SWFFileUpload调用系统底层弹出框无法定位问题

    Webdriver是基于浏览器操作的,当页面上传文件使用的是flash的控件SWFFileUpload调用的时候,调用的是系统底层的文件选择弹出框 这种情况,Webdriver暂时是不支持除页面外的其 ...

随机推荐

  1. mapper映射文件配置之select、resultMap(转载)

    原文地址:http://www.cnblogs.com/dongying/p/4073259.html 先看select的配置吧: <select         <!-- 1. id ( ...

  2. SpringBoot之模板引擎

    一.Thymeleaf 1.1 集成 templates 在 pom.xml 文件中添加依赖 <dependencies> ...... <dependency> <gr ...

  3. 移动端h5模拟长按事件

    为啥写这篇文章 最近接了个需求,要求长按某个标签显示删除一个悬浮的删除按钮.这个需求其实在app上很常见,但是在移动端h5中,我们没有长按的事件,所以就需要自己模拟这个事件了. 大概效果如下: ps: ...

  4. Flask【第11篇】:整合Flask中的目录结构

    整合Flask中的目录结构 一.SQLAlchemy-Utils 由于sqlalchemy中没有提供choice方法,所以借助SQLAlchemy-Utils组件提供的choice方法 import ...

  5. xDSL相关

    ----------------------- --------------

  6. mysql 8.0.16 单主 mgr搭建

    mysql 8.0.16 单主 mgr搭建 环境介绍: 192.168.142.142 db142192.168.142.143 db143192.168.142.145 db145 1.安装依赖包 ...

  7. shell练习--PAT题目1008:数组元素循环右移问题 (失败案例,运行超时)

    一个数组A中存有N(>)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥)个位置,即将A中的数据由(A​0​​A​1​​⋯A​N−1​​)变换为(A​N−M​​⋯A​N−1​​A ...

  8. Git的使用及安装

    1安装. 步骤一 如果是32位就安装32位,64位就安装64,任选一款. 步骤二 步骤三 步骤四 步骤五 步骤六 步骤七 步骤八 步骤九 步骤十 步骤十一 上面的安装完成以后,下面的程序包按要求安装就 ...

  9. node中controller的get和post方法获取参数

    1.get: const body = ctx.query; // get请求   2.post: const body = ctx.request.body; // post请求

  10. js dom 添加类

    var sheng = document.getElementById("sheng"); ; sheng.onclick = function() { if(this.paren ...