loading...

Selenium vs The World Faster Clicker

pjcalvo profile image Pablo Calvo ・2 min read

Today I discovered that a guy named Jordan Hum is the world record holder for more clicks in 5 seconds, with an amazing score of 14 CPS which means 70 clicks in 5 seconds.

So I went to Click Speed Test and tried my self.

You’re a Rabbit! Well.. You Clicked with the speed of 9.6 CPS (Clicks per seconds). You made 48 Clicks in 5 Seconds.

Automating the clicks

I wondered how fast can selenium click? I am pretty sure that a selenium script can beat this guy, but let's make sure finding some results.

This is the script:

driver = webdriver.Chrome(DRIVER_LOCATION) #driver
driver.get("https://clickspeedtest.com/5-seconds.html")
print('Start clicking')
id = driver.find_element_by_id('clicker')
while True: # click for ever
  try:
    id.click() 
  except Exception as ex: # until it breaks
    print('Time is over')
    break

time.sleep(1) # results are slow
result = driver.find_element_by_css_selector('.times')
print(f'Result: {result.text}\n') 
driver.close()

I executed it several times to find an average value, but basically this was the result:

Start clicking
Time is over
Result: 190 Clicks in 5 Seconds

Let's learn something

I wanted to have a lesson learned out of this post, so I tried and tested a couple of myths:

1) The original script finds the element once and then uses that instance to execute the clicks. But what if we try to find the element inside the loop and click it right away driver.find_element_by_id('clicker').click().

The outcome is way slower clicking as expected:

Result: 137 Clicks in 5 Seconds

2) We can try to use a javascript executor to performs the clicks instead of the click method:

javaScript = "document.getElementById('clicker').click();"
driver.execute_script(javaScript);

My lesson learned for this case is that using javascript not always trigger the click event.

3) What if I use a headless browser? Does it makes any difference:

The result is (surprisingly for me) an average faster clicking:

Result: 216 Clicks in 5 Seconds

I executed this a lot of times and in some cases it went down to ~170, but average was mostly faster.

Final thoughts

Maybe clicking this fast is not a normal use case for selenium, but knowing how to improve tests speed and performance can save some minutes of execution on large amounts of tests.

Suggestions on what else we can test?

cheers :) and remember to keep clicking
https://pjcalvo.github.com

if you liked the post:

Buy Me A Coffee

Posted on Jan 29 by:

pjcalvo profile

Pablo Calvo

@pjcalvo

Software developer with a passion for software testing. | Open source contributor

Discussion

markdown guide