January 22, 2019
4 mins.
I have made this project for my personal use and it helped me in a few situations after I wrote this one. You can read about the background story about why I built this. You can also find the basic version of the script for the bot at:
In this post, I’ll briefly explain how I made this bot and what were the problems that I faced and the decisions I made.
First and foremost thing that motivated me to write this bot is that almost 80-90% of questions were based on guess the output types. So, I thought I can write a bot which can directly execute the code that is shown and select the answer based on output. If you want to read in detail about why I built this then read Quiz writer bot blog
To the knowledge that I had at the time I wrote this bot, I know that bots are written based on some common patterns for a given task. The common things or patterns that I found in my particular problem were:
Once I had all the information above I tried to fetch the elements by playing for a while in console in developer tools of the browser. With that, I have all the CSS selectors or XPaths ready for grabbing the elements.
Now I can access the DOM elements that I want but, what about the interactions? How do my bot clicks on correct options and then clicks on the next question, next test, etc.,? To simulate these I chose Selenium, which is used to automate some tests on webpages. My choice of language was python because of 2 reasons, I am very elegant in Python and most of the bots that I heard of is written in Python. So, here is what I did:
pre
or code
tag and write it to a file with .c
extension.run
method exposed in the subprocess
module of python and get the output.difflib
for finding the closest matches and random
module for random choice making.That’s how I wrote a bot to write online tests for me in my hectic schedule 😜.
By Krushi Raj Tula A developer, geek, enthusiast, who loves to solve problems and fix things with technology. You can reach out to him on Twitter!