4

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 similar. The website I am using is javascript based so I can`t really see physical links.

2 Answers 2

5

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)
Sign up to request clarification or add additional context in comments.

Comments

-1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.