How do I get selenium to consistently find and use an element when creating a Kahoot quiz?

I’m creating a auto type answer Kahoot quiz from a spreadsheet using selenium. Here is an excerpt of some of my code below, and a excerpt to some of the table I’m using. Everything else should work, however on lines 87 to 91 it can’t consistently create a new type answer question and on lines 98 to 101 it can’t consistently type out the questions and answers. When something goes wrong with either it’s because the web element couldn’t be found, which confuses me because the code works properly sometimes.

import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

import openpyxl

# put in spreadsheet
df = pd.read_excel('1000 of the most common Spanish Nouns.xlsx')

# Type in your email or username
email = '[email protected]'
password = 'peter7144'

folder_name = input('Folder Name: ')
quiz_question_length = int(input('Length of each quiz: '))

# set up the webdriver
driver = webdriver.Chrome()

# go to kahoot login
driver.get('https://create.kahoot.it/auth/login')

# type kahoot account credentials
driver.implicitly_wait(10)
driver.find_element(By.ID, 'username').send_keys(f"{email}")
driver.find_element(By.ID, 'password').send_keys(f"{password}")

# get rid of potential popup
try:
    driver.find_element(By.CSS_SELECTOR, 'button[id="onetrust-pc-btn-handler"]').click()
    driver.find_element(By.CSS_SELECTOR, 'button[class="ot-pc-refuse-all-handler"]').click()
    print('skipped cookie popup')
except:
    print('no cookie popup')

# press login
driver.find_element(By.CSS_SELECTOR, 'button[id="login-submit-btn"]').click()

WebDriverWait(driver, 30).until(EC.url_contains("create.kahoot.it"))

# skip second popup
try:
    driver.find_element(By.CSS_SELECTOR, 'button[aria-label="Next"]').click()
    driver.find_element(By.CSS_SELECTOR, 'button[aria-label="Next"]').click()
    driver.find_element(By.CSS_SELECTOR, 'a[class="btn btn--text"]').click()
    print('skipped second popup')
except:
    print('no second popup')

# go to kahoot account's library
driver.implicitly_wait(10)
driver.find_element(By.CSS_SELECTOR, 'a[data-functional-selector="side-bar-link__library"]').click()

# create a new folder for kahoot quiz
driver.find_element(By.CSS_SELECTOR, 'button[data-functional-selector="library_side-bar_create-folder"]').click()
driver.find_element(By.CSS_SELECTOR, 'input[placeholder="New folder"]').send_keys(f'{folder_name}', Keys.ENTER)

# split df into multiple different parts
quizzes = []
for i in range(0, len(df), quiz_question_length):
    if i + quiz_question_length < len(df) + 1:
        quizzes.append(df.iloc[i:i + quiz_question_length])
    else:
        quizzes.append(df.iloc[i:])

# begin creating quizzes
for quiz in quizzes:
    # create new kahoot quiz
    driver.implicitly_wait(10)
    driver.find_element(By.CSS_SELECTOR,
                        'button[class="button__Button-sc-c6mvr2-0 iwRYhY create-button__PrimaryButton-sc-1wmq7f8-0 jaZrfx"]').click()
    driver.find_element(By.CSS_SELECTOR, 'button[aria-label="Create new Kahoot."]').click()

    # choose blank option for kahoot quiz
    driver.find_element(By.CSS_SELECTOR, 'button[class="styles__FlowOptionInnerContainer-sc-hcxgxq-2 gmFgAG"]').click()
    driver.find_element(By.CSS_SELECTOR, 'button[class="flat-button__FlatButton-sc-6uljam-0 iEWtrJ"]').click()

    # close the theme panel
    driver.find_element(By.CSS_SELECTOR, 'button[aria-label="Close Themes panel"]').click()

    # PROBLEM WITH ADDING A NEW TYPE ANSWER QUESTION
    for index, row in quiz.iterrows():
        # add new answer type question
        driver.implicitly_wait(5)
        add_question_btn = driver.find_element(By.CSS_SELECTOR, 'button[data-functional-selector="add-question-button"]')
        add_question_btn.click()
        answer_type_btn = driver.find_element(By.CSS_SELECTOR, 'button[data-functional-selector="create-button__open-ended"]')
        answer_type_btn.click()

        # set up question and answer input from spreadsheet
        question_input = row['Question']
        answer_input = row['Answer']

        # PROBLEM WITH ADDING QUESTION AND ANSWER TEXT TO QUESTION
        question_text = driver.find_element(By.CSS_SELECTOR, 'p[data-placeholder="Start typing your question"]')
        question_text.send_keys(question_input)
        answer_text = driver.find_element(By.CSS_SELECTOR, 'input[placeholder="Type an answer"]')
        answer_text.send_keys(answer_input)

Question Answer
la explosión explosion
el apellido last name
la conferencia conference
la intensidad intensity
el paquete package
la propuesta proposal
la botella bottle
el cadáver corpse
la combinación combination
la dama lady
la onda ripple
la torre tower
el afán eagerness
la comisión commission
la llave faucet
la posesión possession
el candidato candidate
el gas gas
el noviembre November
el talento talent
el té tea
el afecto affection
el consumo consumption
la deuda debt
el horizonte horizon
la patria fatherland
la protesta protest

I think what I need to do is have the webdriver wait until it finds the elements it needs clickable or able to be typed, because the elements are definitely there. I’ve heard of using explicit waits for that however I’m unsure how to go about it. I’m a new coder so this may be a little messy and was just a little project I wanted to work on.

New contributor

Richmond Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật