I'm trying to simulate mouse movement across a random curve line or parabola so it looks like the mouse actually moved across the page. With Selenium, I only know how to click on an element but that doesn't simulate a real user on some websites. I want the mouse to move along a random line that I calculate, then click the element.
The Python code would look like this (assuming your browser is Firefox):
driver = webdriver.Firefox(executable_path=driver_path)
action = webdriver.ActionChains(driver)
element = driver.find_element_by_id('your-id') # or your another selector here
action.move_to_element(element)
action.perform()
Please note that this doesn't move your physical cursor, but only invisible cursor of Selenium. To see if it worked, element must have some 'hover' effect. Also if you have already moved your cursor to an element and want to re-position it relatively, you can use:
action.move_by_offset(10, 20) # 10px to the right, 20px to bottom
action.perform()
or even shorter:
action.move_by_offset(10, 20).perform()
More documentation is here: https://selenium-python.readthedocs.io/api.html
The docs say you can use move_by_offset(xoffset, yoffset)
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With