I created a code to perfectly complete a human benchmark quiz. Why does it fail?

Viewed 679

The following is a code i made in an attempt to get a perfect score on this website: https://humanbenchmark.com/tests/verbal-memory

For some reason it fails every time i run it and i cant figure out why.

from selenium import webdriver
import time

driver = webdriver.Chrome("D:\\user\\Downloads\\chromedriver_win32\\chromedriver.exe")

driver.get("https://humanbenchmark.com/tests/verbal-memory")

word_list = []

time.sleep(2)

start_button = driver.find_element_by_xpath("/html/body/div/div/div[4]/div[1]/div/div/div/div[4]/button")
start_button.click()

def click_new():
    new_button = driver.find_element_by_xpath("/html/body/div/div/div[4]/div[1]/div/div/div/div[3]/button[2]")
    new_button.click()

def click_seen():
    seen_button = driver.find_element_by_xpath("/html/body/div/div/div[4]/div[1]/div/div/div/div[3]/button[1]")
    seen_button.click()

while True:
    current_word = driver.find_element_by_class_name("word")
    if current_word.text in word_list:
        click_seen()
    else:
        click_new()
    word_list.append(current_word.text)
    time.sleep(2)
1 Answers

I add the word to the list before clicking on the button:

while True:
    current_word = driver.find_element_by_class_name("word")
    if current_word.text in word_list:
        click_seen()
    else:
        word_list.append(current_word.text)
        click_new()
    time.sleep(2)

Seemingly, current_word is actually updated in the moment you click the button, and then it's already the new word that is added to the list. This one you will then think to have seen, so it always selected click_seen().

I let it run for some time, but I leave the honour to you to break the record and screw the statistics :-DDD.

Related