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)

 

转载于:https://www.cnblogs.com/catleer/p/6288867.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值