Skip to content

Automate browser with Imacros

Browser Automation is a wonderful thing, yet not too popular with non-programmers. Honestly, I don’t get why. There are many tools available – applications, browser addons and extensions, to ease repetitive daily tasks, whether it is business expert opening a set of tabs during specific meetings, tester going through acceptance test routine, or product owner trying to verify whether product still works as expected after the release. It is all nothing but input, output and few clicks in the browser, so it can be easily automated.

To showcase browser automation I have selected Imacros extension and Moz.com website. Imacros extension, because it is easy to use, and it supports action recording. Moz.com because they are assholes. Hence I created this script, and now will be happy to share this approach as an example of what can be achieved with few browser extensions and will to automate.

Automation Setup

Stack I used is very basic, allows to do this in-browser without programming skills. The setup is:

  1. Chrome Browser, Firefox will do too
  2. Imacros browser extension to automate clicks and data scraping – links for Google Chrome, Firefox. With this extension a lot of great things can be automated, what I will showcase is just the tip of the iceberg.
  3. Extra for this use case – Anticaptcha extension to solve Google Re-Captcha – links for Google Chrome, Firefox. This comes with 5 free runs, afterwards costs 10$ for approx. 4600 captcha solves. Custom solution can also be built, but not easily – here’s a PDF with theory. If you know an implementation for this + new changes Google made, with success rate above 70%, ping me, please.

Automation flow

What the Imacros script below is instructing the browser to do:

  1. Open a temporary email site, capture email address
  2. Open Moz registration page
  3. Fill in unique username and password, and above email
  4. Wait for anti-captcha to solve, register
  5. Open email, click on account activation link
  6. Open Moz site API section
  7. Wait for anti-captcha to solve, generate credentials,
  8. Capture credentials, pass them to external API via GET parameters and save in DB
  9. Log out from Moz, delete the temp email

Here’s a quick demo of below script executed through Chrome’s Imacros extension, it is 30 sec representation of a 4 min process:

GIF browserautomate

Macro script

The workflow I used to generate this macro script is pretty straight forward. First used record mode and manually clicked through the flow. Then replaced my email provider with a temporary one. Then replaced copy-paste actions with variable extraction and set. Then found a solution for anti-captcha and added wait times to make sure it runs smooth every time. Finally added delete email and log out functionality to enable looping of the macro.

VERSION BUILD=844 RECORDER=CR
TAB OPEN
TAB T=2
URL GOTO=chrome://newtab/
URL GOTO=https://temp-mail.org/en/
WAIT SECONDS=1
SET !EXTRACT_TEST_POPUP NO
TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:mail EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
SET !EXTRACT NULL
TAB OPEN
TAB T=3
URL GOTO=chrome://newtab/
URL GOTO=https://moz.com/
TAG POS=1 TYPE=A ATTR=TXT:Log<SP>in
TAG POS=1 TYPE=A ATTR=TXT:Create<SP>an<SP>account
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:register-form ATTR=ID:UserDisplayName CONTENT=User{{!NOW:ssnnhhddmmyy}}
TAG POS=1 TYPE=INPUT:EMAIL FORM=ID:register-form ATTR=ID:UserEmail CONTENT={{!VAR1}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:register-form ATTR=ID:UserPassword CONTENT={{!VAR1}}
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:register-form ATTR=ID:tos CONTENT=YES
WAIT SECONDS=45
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:register-form ATTR=ID:register-form-submit
TAB CLOSE
TAB T=2
WAIT SECONDS=60
TAG POS=1 TYPE=A ATTR=ID:click-to-refresh
WAIT SECONDS=5
TAG POS=1 TYPE=SPAN ATTR=CLASS:glyphicon<SP>glyphicon-chevron-right&&TXT:
TAG POS=1 TYPE=P ATTR=TXT:Moz
TAG POS=4 TYPE=TD ATTR=TXT:*You're<SP>almost<SP>done!<SP>Pleas*
WAIT SECONDS=2
TAG POS=1 TYPE=A ATTR=TXT:Activate<SP>Your<SP>Account
TAG POS=R1 TYPE=* ATTR=* EXTRACT=
TAB T=3
URL GOTO=https://moz.com/products/mozscape/access
WAIT SECONDS=3
TAG POS=1 TYPE=DIV ATTR=ID:recaptcha
WAIT SECONDS=45
TAG POS=1 TYPE=BUTTON ATTR=TXT:Generate<SP>Key
WAIT SECONDS=10
TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:access-id EXTRACT=TXT
SET !VAR2 {{!EXTRACT}}
SET !EXTRACT NULL
TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:secret-key EXTRACT=TXT
SET !VAR3 {{!EXTRACT}}
SET !EXTRACT NULL
TAB OPEN
TAB T=4
URL GOTO=chrome://newtab/
URL GOTO=http://example.com/?key={{!VAR2}}&secret={{!VAR3}}
TAB T=3
TAG POS=1 TYPE=IMG ATTR=SRC:https://dc8hdnsmzapvm.cloudfront.net/avatar/large/1/u
TAG POS=1 TYPE=A ATTR=TXT:Log<SP>Out
TAB T=2
TAG POS=2 TYPE=A ATTR=TXT:Delete
TAG POS=1 TYPE=A ATTR=TXT:Welcome<SP>to<SP>Moz.<SP>Check<SP>out
TAG POS=1 TYPE=SPAN ATTR=CLASS:glyphicon<SP>glyphicon-remove&&TXT:
TAG POS=1 TYPE=A ATTR=ID:click-to-delete

With Imacros you can record mouse clicks, inputs, and then replay them; add variables, extract data to .csv, use .csv as data inputs, and so on. It’s not perfect, but does the job pretty well and consistently. I hope this inspires someone to get this or similar browser extension, record daily clicks and save a lot of time. Cheers! 🙂

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *