python selenium mouse scroll wheel click

后端 未结 2 1368
渐次进展
渐次进展 2020-12-17 05:15

I have a question about is it possible to simulate a mouse scroll wheel click in python selenium ( when you click on a link a new tab opens in the browser ) or something sim

2条回答
  •  感动是毒
    2020-12-17 06:06

    You need to execute javascript code. Mouse scroll wheel click has 1 as number representation according to MouseEvent.button documentation:

    0: Main button pressed, usually the left button or the un-initialized state

    1: Auxiliary button pressed, usually the wheel button or the middle button (if present)

    2: Secondary button pressed, usually the right button

    3: Fourth button, typically the Browser Back button

    4: Fifth button, typically the Browser Forward button

    Your javascript code will be

    var mouseWheelClick = new MouseEvent( "click", { "button": 1, "which": 1 });
    document.getElementById('#elementToClick').dispatchEvent(mouseWheelClick)
    

    Then just simply

    driver = webdriver.Firefox()
    driver.execute_script(javascript_code)
    

提交回复
热议问题