Cross browser web scraping with AutoHotkey and Selenium

 

While AutoHotkey is an amazing tool for Web Scraping, many people complain about being limited to connecting with COM to IE.   In the below videos I walk through how you can use AutoHotkey and Selenium to automate web scraping in virtually any browser you wish.  🙂

What is Selenium & why should AutoHotkey users care?

Installing Selenium

In order to control Selenium with AutoHotkey you need to install the SeleniumBasic.  The current version is 2.09.0 and can be downloaded here.  Selenium is now on version 3 and there is a new SeleniumBasic version promised to be released soon which will connect to version 3 of Selenium.  Make sure you download the WebDrivers of choice for your browsers.

If all of this sounds confusing, don’t feel bad.  It is ridculous!  I found this post which documents/clarifies much of the confusion (although Selenium 3 is now out)

Please note several people reported when installing Selenium Basic it did not install in the program files location (i.e. here: C:\Program Files\SeleniumBasic or C:\Program Files (x86)\SeleniumBasic).  They also had problems getting Selenium to launch.   I recommend you make sure Selenium installs into one of the Program Files location and also make sure you get the Selenium drivers installed.  After install I had the following files on my computer:

  • C:\Program Files\SeleniumBasic\operadriver.exe
  • C:\Program Files\SeleniumBasic\chromedriver.exe
  • C:\Program Files\SeleniumBasic\edgedriver.exe
  • C:\Program Files\SeleniumBasic\iedriver.exe

I also updated the Chrome driver here and am keeping my Chrome version up to date (currently on version 59.0.3071.71)

Here are some links you might want to review (but you’ll need to adapt them for your purposes)

Installing Selenium for use with AutoHotkey

 

Using AutoHotkey and Selenium across various browsers

This video I show two ways I’ve learned how to start-up the Selenium Webdriver with AutoHotkey.

Tutorial showing how to start up and navigate with AutoHotkey and Selenium

Using AutoHotkey & Selenium- Starting the browsers & navigating to a page

Getting information from a page with Selenium and AutoHotkey

While there are a lot of similarities to data extraction in Selenium, there are quite a few differences as well. The below code is what I use in the following video.  It demonstrates some ways that you can extract data from a web page via Selenium and AutoHotkey.

 

using AutoHotkey and Selenium : Getting information from a page

Setting information on a page

Selenium and AutoHotkey are pretty different in how you set information.  Selenium has a “sendkeys” method which seems to be pretty reliable at triggering events on a page.

  • Make sure you review this:  Send keys to value:  ;Note: you need to add “driver” e.g. .SendKeys(driver.Keys.ENTER)

Setting text & clicking items on a page with Selenium and AutoHotkey

Selenium and AutoHotkey: Setting text and clicking elements

 

Using your Chrome Profile (Avoiding the need to re-login to a site)

In this video I demonstrate how you can leverage your Chrome profile so you do not need to keep logging into a website with Chrome

 

Setting Selenium Chrome profile with AutoHotkey

Iterating over Objects with Selenium and AutoHotkey

In the below video I demonstrate some of the important differences when iterating over objects with Selenium and AutoHotkey.    A COM based object does not have an enumerator thus you cannot simply use a for-loop to iterate over them.   Selenium does does have an enumerator however the objects are held in the Keys (not the values).

 

Demo video showing how to iterate over objects in Selenium

Various Selenium methods for getting & setting data on a page

In this tutorial I walk through various ways to get/set data on a page. With Selenium you can use both CSS and Xpath which are like QuerySelector.

I also shared these two resources from Michael Sorens which present the same data grouped by Method and grouped by Tool.

 

Selenium & AutoHotkey- Various methods for Getting/Setting data

Various methods from Selenium & by using JavaScript Execution

I went through and documented some of the additinol methods I used from Selenium & by injecting JavaScript. Check them out below as well as the video walking through the usage.

Selenium & AutoHotkey- Methods and JavaScript execution

Maneuvering Frames in Selenium with AutoHotkey

The below code provides some insights on how to navigate frames with AutoHotkey

Navigating Frames with Selenium and AutoHotkey

Downloading files with Selenium and AutoHotkey

In this tutorial I demonstrate how I used AutoHotkey and Selenium to download a PDF file. The same process will work for other files that are not, automatically, opened by Chrome.

Downloading a PDF file with Selenium and AutoHotkey

Comments are closed