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.

J. Doe
  • 183
  • 2
  • 9
  • Possible duplicate of [Human-like mouse movements via Selenium](https://stackoverflow.com/questions/39422453/human-like-mouse-movements-via-selenium) – Chris Jul 14 '18 at 14:17

1 Answers1

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
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • Two questions 1. Does this move my actual mouse 2. If not, would this get detected as regular mouse movements by a given website? – J. Doe Jul 14 '18 at 14:25
  • 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. – cruisepandey Jul 14 '18 at 14:30
  • 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? – J. Doe Jul 14 '18 at 14:32
  • 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. – cruisepandey Jul 14 '18 at 14:36
  • I am scraping fairly large websites there is no way they would ever respond to any emails or inquiries. – J. Doe Jul 14 '18 at 14:38
  • No problem bud. – cruisepandey Jul 14 '18 at 14:46