WebdriverIO – Injecting JavaScript to Capture AJAX Errors

Recently I found a pretty advanced way to automate my social media stuffs:

  1. elgalu’s docker-selenium
  2. Webdriver.io
  3. Social media platform of choice (I’ve done LinkedIn, Facebook and Instagram)

So the idea is that you launch a Docker instance with Selenium grid running on it, and you can choose between Chrome and Firefox on the fly through the Node.js based Webdriver.io code configuration.

I was able to automate myself going through hundreds of posts, and picking out ones with relevancy which may have some kind of monetary value, kind of like lead generation.

Quickly I ran into some issues while doing some Instagram unfollow automation. My script was unfollowing users from a list of 100+ every 20 seconds or so, however Instagram has some limits in place so essentially when Instagram decides I’ve done too many unfollows, it rejects my action of clicking the unfollow button.

This rejection can only be seen in the console of the client, and I needed a way for the browser – via Selenium via Webdriver.io to pass to me, the message that I’ve hit this limit. Essentially it was an AJAX response of 403 forbidden.

Achieving this communication wasn’t straightforward but the below example makes this happen. Hopefully it’s of some use to somebody out there on the internets.

Surely this can be adapted for use on any kind of Selenium based testing wrapper/framework/script.

Write a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.