2

I am scraping some websites using Seleneium that tracks my mouse movements and require that I use my mouse to click on around. Is it possible to simulate mouse movements that would be identified by JavaScript as mouse movements, without moving my actual mouse? I.e. so I could have multiple scripts running and be able to use my own mouse for other things?

I have thought about using a virtual machine but that seems like complete overkill especially because I would need multiple running at the same time.

This is different from Human-like mouse movements via Selenium as the point here is more how to simulate mouse movements that javascript will pick up as regular mouse movements, but wont move your actual mouse, so you can have multiple scripts running and/or use your regular mouse for other things.

1

1 Answer 1

2

You can simulate mouse action through ActionChains in selenium- Python Binding.

Let's say you have a web element like this :

wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, 'someid')))  

You can use action chain like this :

ActionChains(driver).move_to_element(element).perform()  

Note that you have to import from selenium.webdriver.common.action_chains import ActionChains this to use action chain.

Some of the widely used ActionChains methods are :

  1. context_click (right click)
  2. double_click
  3. drag_and_drop
  4. move_to_element
  5. send_keys
Sign up to request clarification or add additional context in comments.

6 Comments

Two questions 1. Does this move my actual mouse 2. If not, would this get detected as regular mouse movements by a given website?
By using this you are simulating the mouse actions such as right click or double click. Ideally you should let your script run without using actual keyboard and actual mouse. Ans 1. It's simulation of your actual mouse.You can still use your mouse , However I would not recommend that. 2. If the website is too restrictive i.e it is able to catch your regular mouse , I am afraid this will be detected by website.
Okay 2 follow up questions. 1. Why would you not use your regular mouse while actions chains would be running? 2. Is there anyway to get around the problem of detection?
Ans 1. Because , I might face this exception Element is not clickable at this point other element would receive the click at (x, y) . and of course for smooth execution of program. 2. you have to talk to dev to give you a test environment in which there is no detection for mouse movement.
I am scraping fairly large websites there is no way they would ever respond to any emails or inquiries.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.