I Created a Code to Perfectly Complete a Human Benchmark Quiz. Why Does It Fail?

The following is a code i made in an attempt to get a perfect score on this website:

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("")

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)
4

1 Answer

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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest