Complete first quesrion, select button, create response vars.
This commit is contained in:
parent
0060d189d9
commit
b05323f41a
46
app.py
46
app.py
@ -25,7 +25,7 @@ driver.get(url)
|
|||||||
wait = WebDriverWait(driver, 10)
|
wait = WebDriverWait(driver, 10)
|
||||||
|
|
||||||
# Mapping of CSV values to radio button IDs
|
# Mapping of CSV values to radio button IDs
|
||||||
radio_button_map = {
|
who_planted_the_trees_map = {
|
||||||
'individual': 'id25',
|
'individual': 'id25',
|
||||||
'organization': 'id27',
|
'organization': 'id27',
|
||||||
'professional': 'id29',
|
'professional': 'id29',
|
||||||
@ -36,25 +36,37 @@ radio_button_map = {
|
|||||||
# Read the CSV file
|
# Read the CSV file
|
||||||
csv_file_path = "surveys/test.csv"
|
csv_file_path = "surveys/test.csv"
|
||||||
with open(csv_file_path, mode='r') as file:
|
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:
|
# Get responses to qestions.
|
||||||
who_planted = row['Who Planted The Tree(s)?'].lower() # Convert to lowercase for consistency
|
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
|
# Answer the Who Planted The Tree(s)? question.
|
||||||
if who_planted in radio_button_map:
|
radio_button_id = who_planted_the_trees_map[who_planted]
|
||||||
radio_button_id = radio_button_map[who_planted]
|
try:
|
||||||
try:
|
# Wait for the radio button to be clickable and click it
|
||||||
# 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 = wait.until(EC.element_to_be_clickable((By.ID, radio_button_id)))
|
radio_button.click()
|
||||||
radio_button.click()
|
except Exception as e:
|
||||||
except Exception as e:
|
print(f"Error selecting '{who_planted}' radio button (ID: {radio_button_id}): {e}")
|
||||||
print(f"Error selecting '{who_planted}' radio button (ID: {radio_button_id}): {e}")
|
# Click Next button.
|
||||||
else:
|
driver.find_element(By.XPATH, '/html/body/div[3]/section[1]/div/div[6]/div[1]/button[2]').click()
|
||||||
print(f"Unknown value in CSV: '{who_planted}', skipping...")
|
|
||||||
|
|
||||||
# Optional: Submit the form if necessary
|
# Answer the Start Date of Planting question.
|
||||||
# driver.find_element(By.ID, 'submit_button_id').click()
|
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
|
# Close the driver
|
||||||
driver.quit()
|
driver.quit()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user