Windows Automation with AutoIt
I know, this post is a bit odd comparing to what I am used to write.
You (developer) are doing your job, when your boss turn to you and say:
- "Hey, let's make a robot to automate the payment routine?!".
- "Ok, what do you need?"
- "It needs to access the bank website, sign in and schedule some payment transactions".
- "Ok, let me try"
Some could think in making use of Selenium to pull it off, but here are some caveats:
- The financial pc runs Windows (the one used to run the robot)
- The bank website uses a Java applet and requires a USB token to sign in
Selenium didn't seem to be the best option for me.
The solution
I was fortunate enough to remember I was told about AutoIt sometime ago, "a scripting language designed for automating the Windows GUI and general scripting".
I had committed myself to play with it someday and this robot seemed a good opportunity.
Most of the code I will show below was taken from internet and adapted for my needs.
Setup
Head to AutoIt website, click Downloads and download the version "AutoIt Full Installation".
Open the SciTE editor and we are ready to develop. Hit F5 to run the program.
GUI
I created a simple GUI which contains an input text to enter the date to schedule the payments and a button responsible for calling the "goPay" function.
Reading and validating the input
In the first lines of "goPay" I read and validate the input:
If the date is empty, I display a pop up and return.
Creating a browser instance
AutoIt has built-in support for the Internet Explorer browser, it's not the best, but does the job.
In my case, if the pc has the USB token connected, we don't need to type user/password, just the token password.
Notice we use {}
to type the "ENTER" key. You can see others commands here.
Reading and iterating over a CSV file
We need to read the payments destination from somewhere, a CSV file seems good:
Navigating through the links
All the links in the bank website I was accessing were handled by JavaScript code, so I had to navigate using mouse movements and clicks.
Conclusion
These are the pieces we need to make the robot, the rest is a combination of mouse movements and keystrokes.
Don't forget to close the IE instance in the end:
AutoIt is a good tool to have in your tool belt, once you are done with your script, you can export it into a standalone .exe file that does not require runtime libraries using the Aut2Exe
(comes in the full installation).
Enjoy yourself.