How I Saved Corporate Money By Writing A Script – PyAutoMouse

I was faced with a very long survey.

The online survey consists of 80+ questions with each question taking up to 5 mouse clicks.

My team is facing the reality of having to answer this survey multiple times.

So I stepped forward and wrote a script that can automate this process. And here’s how I wrote it.

The Problem

The problem was that my team will have to answer this survey multiple times, and this activity is too time-consuming, not to mention taking the test, in our context, is mindless.

The POSSIBLE APPROACHES

I saw three possible approaches how I can automate this and solve the problem:

  1. Automate via Javascript
  2. Use Selenium IDE
  3. Write a Python script

I took the Javascript path first thinking this road will be much faster. Though, I faced two problems:

  1. The Javascript functions that were being used by the system, which I wanted to use, are not accessible due to the site being contained in an iFrame.
  2. The DOM elements that I need to interact with do not have a unique identifier. Though I can find a way to bypass this, but that will make the code unnecessarily complex.

So I moved to try my hand at Selenium IDE. Then I found out that the survey doesn’t really like it (e.g. laggy, unoptimized DOM design)

Alas, what other option could there be? Could this be the perfect opportunity to try my hand at Python and sharpen my skills?

The Solution

With a few reviews and a few Google searches, I wrote the Python script in a single sitting. Attached below is a screenshot of the entire source code:

The automation script uses three modules, mainly depending on the external library pyautogui. The code takes in five declared coordinates where the mouse will click in a sequential manner while running under a loop, with a declared delay variable as a fail-safe. I also wrapped the main logic so that it will listen for keyboard interruptions — Another layer of fail-safe (we don’t want our mouse to click on something that we should not).

This is how the script works: The application hijacks the mouse and automates the user behavior by automatically clicking on the survey buttons under configurable parameters (e.g. mouse speed, button coordinates, number of loops)

Below is the end result of my automation script:

Imagine me sitting back, with my hands on the back of my head, watching my computer do all the work for me.

And of-course I can configure it such that it executes at lightning speed.

Much better and faster than human input.

And that’s how I saved company resources and client money. This gave me extra capacity to do creative work instead, while also allowing my team to focus on their development priorities instead of mindless tasks.

Moving Forward

This tool was written only for my specific needs, and there are certainly a lot of room for improvement that I can explore, namely:

  1. Better fail safe mechanisms
  2. User-friendly customizations of parameters
  3. Application behavior customizations

With that said, I unintentionally knocked down yet another of my 2020 goals. Praise God!

PS: To the techy geeks and the aspirants, the source code is available here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s