mardi 24 janvier 2023

I cannot find the xpath for the radio button which should be random using selenium

I cannot find the XPath or the class name for the radio button which should select color randomly from the list using selenium in a google form(link). Other name, age, country, and email are working fine with the xpath. Every time getting an error comes up. Can anyone help me? Code is -

from selenium import webdriver
from faker import Faker
import random
driver = webdriver.Chrome()
driver.get("https://forms.gle/PL3W5TxZVVJHRa1W9")
faker = Faker()

colors = ["green", "blue", "black", "red"]


for i in range(20):
    name = faker.name()
    age = random.randint(18, 99)
    country = faker.country()
    email = faker.email()
    color = random.choice(colors)
    name_field = driver.find_element('xpath','//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/input')
    name_field.send_keys(name)
    age_field = driver.find_element('xpath','//*[@id="mG61Hd"]/div[2]/div/div[2]/div[2]/div/div/div[2]/div/div[1]/div/div[1]/input')
    age_field.send_keys(str(age))
    country_field = driver.find_element('xpath','//*[@id="mG61Hd"]/div[2]/div/div[2]/div[3]/div/div/div[2]/div/div[1]/div/div[1]/input')
    country_field.send_keys(country)
    email_field = driver.find_element('xpath','//*[@id="mG61Hd"]/div[2]/div/div[2]/div[4]/div/div/div[2]/div/div[1]/div/div[1]/input')
    email_field.send_keys(email)
    color_field = driver.find_element("class name",'//div[@class="mG61Hd"]')
    color_field.send_keys(color)


    submit_button = driver.find_element_by_css_selector("[type='submit']")
    submit_button.click()


driver.quit()



Aucun commentaire:

Enregistrer un commentaire