10fastfingers.com and Selenium

Walid Hadri
5 min readDec 24, 2020

In this article, I tried to sum up my little project that I did for fun using Selenium on 10fastfingers.com.

10fastfingers.com:

10fastfingers is a free website that offers typing speed test games in multiple languages. I personally have been using it for a while for fun and to practice my typing skills for a faster coding. You can try it yourself, there is a scoreboard to evaluate yourself by clicking here. My highest score is 87WPM (word per minute), my mean score is 75WPM. But now, I will use Selenium to go higher.

Selenium

Selenium is a free (open-source) web testing tool which uses simple scripts to run test directly within a browser. Many languages can be used to run Selenium test scripts like Java, C#, PHP… I will be using Python.

Selenium has different components with different uses, in this project I am using the WebDriver component and the simple functionality that it makes you able to send commands and get back answers from a browser, in other words it directly communicates with the browser and controls it. If you already know about WebScraping tools like BeautifulSoup or Scrapy, you may have some questions as I did at first, like what is the difference between the three tools and why would I choose Selenium over the two others? You can check this article, it covers the answers.

What is the purpose?

In one of the games on the website, there is a list of words that you are supposed to type, and based on how many words you are able to type in 60 seconds you get a score.

This list changes every time we refresh the page, that means that there is a JavaScript code that comes with this list and that the list is not already written in HTML core page. This is a very important thing to notice. Because we are going to be getting this information from the JavaScript code and not the HTML code.

Once we get the list of words, we have to send it back to the browser as if a person typed them, so the process goes like this:
1. Get the list of words and find the input field where we are supposed to write
2. Print the words (the speed at which we send the words to the browser will be discussed later)

1. Get the list of words and find the input field:

A simple inspect of elements shows that, in the HTML code, there is a division with id=”words” where we have the list of words we are looking for.

In the console, a simple print of the variable words shows that it is the array we are looking for.
Now, we know what we should ask the browser to get the array, let’s jump into Python.

With these few lines, we got the list of words and the input field. In fact, Selenium is easy and friendly for beginners.

2. Sending the list of words:

The next step is to send to the browser the list of the words, more precisely write them in the input field, one by one with a space in between. The question now, is how do we send them? all at a time? put some time.sleep between sending each word or each letter?

2.1 Full Speed/ all at a time

We send the words one by one by looping through the list without any time delay.

This way we get to the top 1% with a score of more than 310WPM but depends on the length of the list, it is not always the same.

2.2 Put a constant time sleep to get a score:

Suppose that I want to get some given possible score, for example a score around 60WPM, if I put the right time sleep between sending each word, I would be able to do that. I added a constant time sleep, we can think about other distributions ( Gaussian….), but the idea is the same.

We should add a condition to verify that the time is still going, otherwise we stop sending the words.

2.2 Send a word (letter) at each keystroke:

This is a fun way to feel like you are the one doing the work when you are not, the idea is for each keystroke whether accurate or not we are going to send the correct word (we could do it letter by letter).
We need to handle keyboard events, for this purpose I used pynput which is a library that allows to control and monitor input devices. This way, I am going to listen to the keyboard strokes, every time I get one I send a word.
I have added three exceptions, to handle time out, finishing the list of words and keystroke to stop [Esc] and exit the game.

3. Wrap up everything with a user interface

For this purpose I used the package PySimpleGUI that enables you to create GUIs. It looks like this:

For the sake of demonstration, I have added the three next videos

FullSpeed
Controlled Speed
KeyStroke

If you are interested, you can check the code here.

--

--