Complete first quesrion, select button, create response vars.

This commit is contained in:
Nick Hepler 2025-02-20 22:36:04 -05:00
parent 0060d189d9
commit b05323f41a

34
app.py
View File

@ -25,7 +25,7 @@ driver.get(url)
wait = WebDriverWait(driver, 10)
# Mapping of CSV values to radio button IDs
radio_button_map = {
who_planted_the_trees_map = {
'individual': 'id25',
'organization': 'id27',
'professional': 'id29',
@ -36,25 +36,37 @@ radio_button_map = {
# Read the CSV file
csv_file_path = "surveys/test.csv"
with open(csv_file_path, mode='r') as file:
csv_reader = csv.DictReader(file)
surveys = csv.DictReader(file)
# Iterate through each survey in the CSV.
for survey in surveys:
for row in csv_reader:
who_planted = row['Who Planted The Tree(s)?'].lower() # Convert to lowercase for consistency
# Get responses to qestions.
who_planted = survey['Who Planted The Tree(s)?'].lower()
start_date = survey['Start Date of Planting']
end_date = survey['End Date of Planting']
num_trees = survey['End Date of Planting']
# Check if the value is in the radio button map
if who_planted in radio_button_map:
radio_button_id = radio_button_map[who_planted]
# Answer the Who Planted The Tree(s)? question.
radio_button_id = who_planted_the_trees_map[who_planted]
try:
# Wait for the radio button to be clickable and click it
radio_button = wait.until(EC.element_to_be_clickable((By.ID, radio_button_id)))
radio_button.click()
except Exception as e:
print(f"Error selecting '{who_planted}' radio button (ID: {radio_button_id}): {e}")
else:
print(f"Unknown value in CSV: '{who_planted}', skipping...")
# Click Next button.
driver.find_element(By.XPATH, '/html/body/div[3]/section[1]/div/div[6]/div[1]/button[2]').click()
# Optional: Submit the form if necessary
# driver.find_element(By.ID, 'submit_button_id').click()
# Answer the Start Date of Planting question.
radio_button_id = who_planted_the_trees_map[who_planted]
try:
# Wait for the radio button to be clickable and click it
radio_button = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[3]/section[1]/div/div[6]/div[1]/button[2]')))
radio_button.click()
except Exception as e:
print(f"Error selecting '{who_planted}' radio button (ID: {radio_button_id}): {e}")
# Click Next button.
driver.find_element(By.XPATH, '/html/body/div[3]/section[1]/div/div[6]/div[1]/button[2]').click()
# Close the driver
driver.quit()