python selenium mouse scroll wheel click

后端 未结 2 1363
渐次进展
渐次进展 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)
    
    0 讨论(0)
  • 2020-12-17 06:07

    You need to execute some javascript code.

     browser.execute_script("window.scrollBy(0,500)")
     time.sleep(3)
     browser.execute_script("window.scrollBy(0,500)")
     time.sleep(3)
    

    This command to scroll the mouse down two times.

    0 讨论(0)
提交回复
热议问题