-1
def runn():
    allanswpos = driver.find_elements(By.XPATH,"//span[@class='answerText']")
    for i in range(0,11):
        for x in range(0,4):
            if (allanswpos[x].get_attribute('innerHTML')).strip()==myanswer:
                answpos = allanswpos[x]
                parent = answpos.find_element(By.XPATH,"..")#This is the correct parent!
                answbox = parent.find_element(By.CLASS_NAME,"answerBox") #This is the correct answer box!
                ansboxclick = answbox.find_element(By.NAME,"checkboxtag")
                time.sleep(3.5)
                ansboxclick.click()
                time.sleep(3)#This is required to make it work
                nextloc = driver.find_element(By.XPATH,"//*[@id='nextQuestion']")
                nextloc.click()
runn()

How do I repeat the function runn() eleven times? I have tried using the following for loop as above(which runs it once then gives a selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document error),

I have tried inserting a for loop around runn() at the end, but it outputs the same error.

How do I repeat

0

Your Answer

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

Browse other questions tagged or ask your own question.