【环境信息】

python3.6+Selenium3.0.2+Firefox50.0+win7

【ActionChains类鼠标事件的常用方法】

1、右击:context_click()

2、双击:double_click()

3、拖动:drag_and_drop()

4、鼠标悬停在一个元素上:move_to_element()

5、按下鼠标左键在一个元素上:click_and_hold()

【问题】

在调用perform()方法时报错,不知道是不是环境配置问题,调用ActionChains中的click方法或者把perfom中的action方法去掉后不会报错,但是达不到效果。

报错信息:

Error
Traceback (most recent call last):
File "D:\Users\chenle\PycharmProjects\untitled\test\MouseOperate.py", line 57, in test_rightClick
ActionChains(self.driver).context_click(username).perform()
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\common\action_chains.py", line 74, in perform
action()
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\common\action_chains.py", line 225, in <lambda>
Command.MOVE_TO, {'element': to_element.id}))
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: POST /session/32d7ba0e-d8b9-4ad2-8c8f-843f9f627b28/moveto did not match a known command

代码:

    def testRightClick(self):
self.MousOperate()
#定位右击的元素,并且多选元素进行右击操作
elements = self.driver.find_element_by_xpath("//div[@class='list-view']/dd[1]/div[2]/div[2]/div")
elements = self.driver.find_element_by_xpath("//div[@id='layoutMain']")
#print(elements.get_attribute('class'))
time.sleep(2)
ActionChains(self.driver).context_click(elements).perform()
time.sleep(5)

9 Python+Selenium鼠标事件的更多相关文章

  1. python selenium --鼠标事件

    转自:http://www.cnblogs.com/fnng/p/3288444.html 本节重点: ActionChains 类 context_click()  右击 double_click( ...

  2. python+selenium 鼠标事件操作

    一.前言 除了可以使用 click( ) 来模拟鼠标的单击操作,现在Web产品中还提供了更丰富的鼠标交互方式,例如鼠标右键.双击.悬停.拖动等功能,在WebDriver中,将这些关于鼠标操作的方法都封 ...

  3. python+selenium_鼠标事件

    引言--在实际的web产品测试中,对于鼠标的操作,不单单只有click(),有时候还要用到右击.双击.拖动等操作,这些操作包含在ActionChains类中. 一.ActionChains类中鼠标操作 ...

  4. selenium 鼠标事件操作

    1.操作鼠标事件的类:ActionChains  perform()  执行所有ActionChains中存储的行为 context_click()  右击 double_click()   双击 d ...

  5. Python+selenium鼠标、键盘事件

    鼠标操作 现在的Web产品提供了丰富的鼠标交互方式,例如鼠标右击.双击.悬停.甚至是鼠标拖动等功能,在Webdriver中,将这些关于鼠标操作的方法封装在ActionChains类提供. 1.鼠标右击 ...

  6. python selenium鼠标键盘操作(ActionChains)

    用selenium做自动化,有时候会遇到需要模拟鼠标操作才能进行的情况,比如单击.双击.点击鼠标右键.拖拽等等.而selenium给我们提供了一个类来处理这类事件--ActionChains sele ...

  7. python + selenium相关事件和元素定位

    女友由于工作上的失误,将公司RDM中的某一字段的2000条数据给删除了.....就算是重新添加字段,但是与其他数据的关联性已经不在了.由于每天的数据修改量大,有关部门不愿意恢复数据库,因此只能一条条的 ...

  8. python selenium ---键盘事件

    转自:http://www.cnblogs.com/fnng/p/3258946.html 本节重点: l 键盘按键用法 l 键盘组合键用法 l send_keys() 输入中文运行报错问题 键盘按键 ...

  9. Python+Selenium - 鼠标操作

    鼠标操作类:action_chains模块的ActionChains类 使用组成:操作 + 执行(perform()) 导入代码 from selenium.webdriver.common.acti ...

随机推荐

  1. [jQueryUI] – Chosen:select下拉选择框美化插件及问题

    Chosen 是一个支持jquery的select下拉框美化插件,它能让丑陋的.很长的select选择框变的更好看.更方便.不仅如此,它更扩展了select,增加了自动筛选的功能.它可对列表进行分组, ...

  2. css设置层级显示

    效果: 代码: <li id="tabIdcontent4" class="nomal" tabid="content4" style ...

  3. UITableviewCell 重用内存

    转载自:http://www.cnblogs.com/tangbinblog/p/3371545.html 重用实现分析 查看UITableView头文件,会找到NSMutableArray*  vi ...

  4. UIView(包括子类)的几个初始化时执行动作的时机

    转载自:http://www.tqcto.com/article/mobile/56963.html 根据你需要执行的动作, 这里有几个方法: -(id)initWithFrame:(CGRect)f ...

  5. expected: file:///

    [java] java.lang.IllegalArgumentException: Wrong FS: hdfs://192.168.190.128:9000/user/hadoop/output/ ...

  6. HDU 3715 Go Deeper

    二分答案 + 2-SAT判断 #include<cstdio> #include<cstring> #include<cmath> #include<vect ...

  7. Posix消息队列实现机制

    本文是对<Unix 网络编程 卷2:进程通信>的笔记. 引言 消息队列是进程间通信的一种方式,可是如果不理解他的实现原理,会有众多不理解之处,下面就结合本书中的例子,对posix消息队列来 ...

  8. 用Java开源项目JOONE实现人工智能编程

    http://www.robotsky.com/ZhiN/MoS/2011-08-25/13142461416649.html 用Java开源项目JOONE实现人工智能编程 https://sourc ...

  9. jQuery Mobile 自定义按钮图标

    自定义css样式---红色部分必须加上 .ui-icon-user-black:after {background:url('../image/user-black.png') no-repeat 0 ...

  10. Android网络开发之OkHttp--基本用法POST

    1.OkHttp框架使用了OkIo框架,不要忘记下OkIo.jar 2.通过POST访问网络,和通过GET访问网络基本相同,多了设置请求参数的过程.主要分为五步: (1).声明并实例化一个OkHttp ...