not sure what the Title should be, please feel free to edit. I am new to Selenium, and was just playing around with it. I tried to experiment on one of my favorite site(10fastfingers.com) which I frequently use for practicing typing. I tried to automate the typing using the latest versions of both Selenium and Python(3.5.*). The automation works, but is REALLY REALLY slow.
Here is my sample script, I have no idea why it is slowing down. Would be great it someone would help me out here. I was expecting the script to go more than 100 WPM, but it only reaches 37 WPM
Problem is, only two lines of words are visible, so, it does not take all the words at once, The words keep appearing as you keep typing them. So, I could not take in all the words at once, and store it in a list, and then loop over them later.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://10fastfingers.com/typing-test/english")
input = driver.find_element_by_id("inputfield")
for i in range(300):
word = driver.find_element_by_class_name("highlight")
word = word.text
print("Typing word ", word)
input.send_keys(word)
input.send_keys(Keys.SPACE)
UPDATE
I tried getting all the words before instead of using find_element_*
inside the loop as suggested by @alecxec. For this, I had to use, BeautifulSoup to parse the HTML, as it was in String format,and I could not use any of the find_element_*
functions on it. The following script improved the Typing Speed to 138 WPM. But, I noticed that the first 20 seconds of typing is REALLY fast, and then the speed starts falling gradually. Please feel free to try out the script on you machine, and let me know the result of the test(WPM) that the script achieved on your system. Maybe it depends on the system configuration as well. I don't know. Is this some memory issue? or Code issue? Any idea how i can fix this.
Modified code
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
driver = webdriver.Firefox()
driver.get("http://10fastfingers.com/typing-test/english")
input = driver.find_element_by_id("inputfield")
script = "return document.getElementById('row1').innerHTML"
all_words= driver.execute_script(script)
soup = BeautifulSoup(all_words, 'html.parser')
words = soup.find_all('span')
for word in words:
text = word.text
input.send_keys(text + Keys.SPACE)
UPDATE 2
I restarted my system, and closed all other applications, and the script ran like magic, it typed all 361 available words before the timer even reached 60 secs, and the result was 361 WPM. So, this does depends on the available RAM.