9 Python+Selenium鼠标事件
【环境信息】
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鼠标事件的更多相关文章
- python selenium --鼠标事件
转自:http://www.cnblogs.com/fnng/p/3288444.html 本节重点: ActionChains 类 context_click() 右击 double_click( ...
- python+selenium 鼠标事件操作
一.前言 除了可以使用 click( ) 来模拟鼠标的单击操作,现在Web产品中还提供了更丰富的鼠标交互方式,例如鼠标右键.双击.悬停.拖动等功能,在WebDriver中,将这些关于鼠标操作的方法都封 ...
- python+selenium_鼠标事件
引言--在实际的web产品测试中,对于鼠标的操作,不单单只有click(),有时候还要用到右击.双击.拖动等操作,这些操作包含在ActionChains类中. 一.ActionChains类中鼠标操作 ...
- selenium 鼠标事件操作
1.操作鼠标事件的类:ActionChains perform() 执行所有ActionChains中存储的行为 context_click() 右击 double_click() 双击 d ...
- Python+selenium鼠标、键盘事件
鼠标操作 现在的Web产品提供了丰富的鼠标交互方式,例如鼠标右击.双击.悬停.甚至是鼠标拖动等功能,在Webdriver中,将这些关于鼠标操作的方法封装在ActionChains类提供. 1.鼠标右击 ...
- python selenium鼠标键盘操作(ActionChains)
用selenium做自动化,有时候会遇到需要模拟鼠标操作才能进行的情况,比如单击.双击.点击鼠标右键.拖拽等等.而selenium给我们提供了一个类来处理这类事件--ActionChains sele ...
- python + selenium相关事件和元素定位
女友由于工作上的失误,将公司RDM中的某一字段的2000条数据给删除了.....就算是重新添加字段,但是与其他数据的关联性已经不在了.由于每天的数据修改量大,有关部门不愿意恢复数据库,因此只能一条条的 ...
- python selenium ---键盘事件
转自:http://www.cnblogs.com/fnng/p/3258946.html 本节重点: l 键盘按键用法 l 键盘组合键用法 l send_keys() 输入中文运行报错问题 键盘按键 ...
- Python+Selenium - 鼠标操作
鼠标操作类:action_chains模块的ActionChains类 使用组成:操作 + 执行(perform()) 导入代码 from selenium.webdriver.common.acti ...
随机推荐
- qt博客
http://blog.csdn.net/foruok/article/category/418962/1
- 常用的dos命名
注销:logoff 注册表:regedit 查看显存:dxdiag 删除文件: del +文件 删除文件夹: rd+(/s)+文件名 (/s表示删除文件下的子目录和文件); 系统配置实用程序: msc ...
- Binary Watch
Binary Watch 描述 Consider a binary watch with 5 binary digits to display hours (00 - 23) and 6 binary ...
- initWithNibName与viewDidLoad的执行关系以及顺序
转载自:http://www.java123.net/v/380331.html 一个ViewController,一般通过init或initWithNibName来加载.二者没有什么不同,init最 ...
- SVN MERGE 和冲突
摘要:最佳做法是避免冲突.冲突时,不要把branch merge到trunk. 先由最新版本的trunk得到branch,然后再修改文件,直接merge过去就行.这样不会有冲突.先用svn merge ...
- 高橋君とホテル / Tak and Hotels
高橋君とホテル / Tak and Hotels Time limit : 3sec / Stack limit : 256MB / Memory limit : 256MB Score : 700 ...
- fuel健康检查Heat失败的原因
service openstack-heat-engine restart chkconfig --level 2345 openstack-heat-engine on
- CodeForces 614D Skills
排序+枚举+二分 最大的那些变成A,小的那部分提高最小值 #include<cstdio> #include<cstring> #include<cmath> #i ...
- Linux命令 理解
RPM常用命令参数列表 1.安装一个包 # rpm -ivh 2.升级一个包 # rpm -Uvh [注意U一定要大写] -i 安装 -U 升线安装 -h 以#显示安装进度 -v 显示附加 ...
- Cocos2dx 学习笔记整理----开发环境搭建
最近在学习cocos2dx,预备将学习过程整理成笔记. 需要的工具和环境整理一下: 使用的版本 cocos2dx目前已经出到了v3.1.1,学习和项目的话还是用2.2.3为宜,毕竟不大想做小白鼠,并且 ...