I was doing something in my project too for Spotify. This is the function I wrote to select genders which are in span html tags.
Libraries Required
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import random
Defining Variables
gender_male = wait.until(EC.presence_of_element_located((By.XPATH, "//span[text()='Male']")))
gender_female = wait.until(EC.presence_of_element_located((By.XPATH, "//span[text()='Female']")))
non_binary = wait.until(EC.presence_of_element_located((By.XPATH, "//span[text()='Non-binary']")))
other = wait.until(EC.presence_of_element_located((By.XPATH, "//span[text()='Other']")))
pnts = wait.until(EC.presence_of_element_located((By.XPATH, "//span[text()='Prefer not to say']")))
Using Random
gender_guess = random.randint(1, 5)
if gender_guess == 1:
gender_male.click()
elif gender_guess == 2:
gender_female.click()
elif gender_guess == 3:
non_binary.click()
elif gender_guess == 4:
other.click()
elif gender_guess == 5:
pnts.click()
Full Code
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
gender_male = wait.until(EC.presence_of_element_located((By.XPATH, "//span[text()='Male']")))
gender_female = wait.until(EC.presence_of_element_located((By.XPATH, "//span[text()='Female']")))
non_binary = wait.until(EC.presence_of_element_located((By.XPATH, "//span[text()='Non-binary']")))
other = wait.until(EC.presence_of_element_located((By.XPATH, "//span[text()='Other']")))
pnts = wait.until(EC.presence_of_element_located((By.XPATH, "//span[text()='Prefer not to say']")))
gender_guess = random.randint(1, 5)
if gender_guess == 1:
gender_male.click()
elif gender_guess == 2:
gender_female.click()
elif gender_guess == 3:
non_binary.click()
elif gender_guess == 4:
other.click()
elif gender_guess == 5:
pnts.click()
Hopefully this helped.