zoukankan      html  css  js  c++  java
  • 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:UserschenlePycharmProjectsuntitled	estMouseOperate.py", line 57, in test_rightClick
        ActionChains(self.driver).context_click(username).perform()
      File "C:Program FilesPython36libsite-packagesseleniumwebdrivercommonaction_chains.py", line 74, in perform
        action()
      File "C:Program FilesPython36libsite-packagesseleniumwebdrivercommonaction_chains.py", line 225, in <lambda>
        Command.MOVE_TO, {'element': to_element.id}))
      File "C:Program FilesPython36libsite-packagesseleniumwebdriver
    emotewebdriver.py", line 236, in execute
        self.error_handler.check_response(response)
      File "C:Program FilesPython36libsite-packagesseleniumwebdriver
    emoteerrorhandler.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)
  • 相关阅读:
    DDD之3实体和值对象
    DDD之2领域概念
    DDD之1微服务设计为什么选择DDD
    SOFA入门
    COLA的扩展性使用和源码研究
    kafka可插拔增强如何实现?
    请设计一个核心功能稳定适合二开扩展的软件系统
    如何保证kafka消息不丢失
    kafka高吞吐量之消息压缩
    kafka消息分区机制原理
  • 原文地址:https://www.cnblogs.com/catleer/p/6288867.html
Copyright © 2011-2022 走看看