1

I am trying to simulate an open webpage then send a mouse click at a certain set of coordinates.

I'm wanting this event to take place in the background without actually opening a browser or moving the mouse.

for example, open www.google.com and click submit(as a set of coordinates) without actually opening the site on the screen

Is this even possible?

Edit: site may also contain javascript

NeonLights86
  • 153
  • 1
  • 8
  • Not sure, but maybe this could help:https://en.wikipedia.org/wiki/Headless_browser – Jacques de Hooge Jul 09 '15 at 18:46
  • Thanks, I feel like this is the direction I need to head. I need to edit my original post because I need it to handle java script. – NeonLights86 Jul 09 '15 at 19:09
  • 2
    [Selenium](http://www.seleniumhq.org/) is a library for automating browsers. You can run the browser in headless mode as mentioned in the above comment. – Zenadix Jul 09 '15 at 19:54

1 Answers1

1

I'd recommend using Selenium.
You'll need to download the Chrome or Firefox webdriver to start off.

Here's an example skeleton:

from selenium import webdriver

# Create a new instance of the Chrome driver
driver = webdriver.Chrome('C:\chromedriver\chromedriver.exe')

# go to the google
driver.get("http://www.google.com")

# click stuff using xpath
driver.find_element_by_xpath('//*[@id="lst-ib"]').click()

# click stuff using coordinates
elem = find_element_by_selector(selector)
ac = ActionChains(browser)
ac.move_to_element(elem).move_by_offset(x_off, y_off).click().perform()

driver.quit()

ActionChains API code courtesy of Dirk Bergstrom

Community
  • 1
  • 1
isopach
  • 1,783
  • 7
  • 31
  • 43