As a keyboard enthusiast, my friends and I always try to find the most comfortable, ergonomic, and aesthetically-pleasing mechanical keyboard that not only sounds pleasing to the ear, but also enables us to type as accurately and efficiently as possible. To test our keyboards, we always compete through various typing test sites, such as 10fastfingers and Monkeytype. Recently, my friend had surpassed 100wpm and as competitive as I am, I wanted to beat him. I thought it'd be a great idea to create a bot that would help me complete typing tests.
There are many libraries that are used by web scraping developers, namely Beautiful Soup, Scrapy, and Selenium. I decided to use Selenium because of its powerful browser capabilities and its popularity in creating bots.
In order to create the bot, I created a WebDriver object with Selenium that would control the DOM objects in the browser. From there, I had to familiarize myself with various Selenium methods and HTML in order to get the data I want. In this case, it is the highlighted word. I also needed to consider how to input the target word into the input field and how to incorporate the timer as a constraint.
The Selenium library allows me to find different DOM objects by class or identifier, so I used the various methods to get the highlighted word, and identify the timer and input field. Once I identified the different elements, I was able to manipulate them as I needed.
Other Selenium methods that were significant and fundamental for the bot to work properly were send_keys()
and sleep()
. I used send_keys()
to simulate a pressed button, or in this case, the enter key. sleep()
was essential for loading the webpage initially and also for timing.
Upon testing, the bot was able to open up an incognito browser, load the webpage, complete the typing test within the time limit, and also close the window.
After running multiple tests, I observed that the results were inconsistent. The final summaries would show various accuracies below 100% and the wpm would range from 200 to 300+ wpm. These discrepancies could be explained by a poor connection, or a delay caused by insufficient locating of the correct DOM element in the source code.
I also ran into a Selenium error for an "invalid session id" which would crash the bot and close the browser without warning. This was resolved after I reset the cache of my browser.
One improvement I could make is for the driver of the web crawler. Selenium requires the driver to be compatible with the browser version, so if the driver were to be outdated, then there could be repercussions on the performance of the bot. I could implement an automatic driver download when I run the bot so that I wouldn't need to update it manually.
Since the time of creation, Selenium has updated its own features so other improvements I could make are updating the deprecated services.
https://selenium-python.readthedocs.io/api.html