Bottom Line: This AppleScript uses jQuery to click a submit button on a webpage over and over in the background while you keep browsing.

Every once in a while, I run across some kind of website or online module where I have to click a Submit button on a page, wait 3 or 4 seconds for the next page to load, click Submit on the next page, wait again… repeat 5 or 10 times, and usually take some kind of quiz afterwards. Often, there are 10 or 15 of these modules.

Sometimes the content is excellent, new to me, and I learn a lot. On fortunately rare occasion, the content is old hat, and I really just need to click that Submit button a bunch of times to get to the darn quiz. On such occasions, the 4 seconds * 8 pages * 10 modules (in reality only 5 minutes or so) of wasted time seems excruciating.

So, my ever-efficient solution was to spend a half hour writing a script to help automate the process.

I don’t know any javascript, so first, I figured out how to import jQuery into a page that didn’t already have it using Chrome’s javascript console (thanks to Stack Overflow).

Then, I figured out how to select and click the Submit button in jQuery.

Next, I couldn’t find a good way to run a while true loop to have the jQuery continue to hit the button when the next page came up (I’m guessing because navigating to the next page reloaded the javascript stuff, purging the script I’d run previously). Instead, knowing that Chrome has decent AppleScript support, and that it can run javascript through AppleScript, I figured AppleScript seemed like a reasonable way to get the job done. (It looks like splinter and selenium would have been an option in Python.)

All that was left was a little polish to make the script exit when the button is no longer found, notify the user at that point, and try to return to the tab in question.

The icing on the cake is that it seems to run just fine in the background, while you continue to browse in other tabs.

Hope you can find some use for it! If so, you may be interested in one of my first scripts, which automates checking a bunch of boxes (on a single webpage).