Skip to content

Instantly share code, notes, and snippets.

@jin-park
Created September 7, 2022 23:33
Show Gist options
  • Save jin-park/cc00d82634e32261c92d53b17a06136f to your computer and use it in GitHub Desktop.
Save jin-park/cc00d82634e32261c92d53b17a06136f to your computer and use it in GitHub Desktop.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)
student_id = "REPLACE_WITH_STUDENT_ID"
name = "REPLACE_WITH_NAME"
window_count = 1
while True:
if len(driver.window_handles) > window_count:
driver.switch_to.window(driver.window_handles[-1])
window_count += 1
url = driver.current_url
if "docs.google.com" in url:
question_blocks = driver.find_elements(By.CSS_SELECTOR, "div.geS5n")
name_student_num = question_blocks[0]
form = name_student_num.find_element(By.CSS_SELECTOR, "input.whsOnd.zHQkBf")
driver.execute_script("arguments[0].disabled=false", form)
form.send_keys(f"{student_id} {name}")
gender = question_blocks[1]
room = question_blocks[2]
gender_options = gender.find_elements(By.CSS_SELECTOR, "div.AB7Lab.Id5V1")
driver.execute_script("arguments[0].disabled=false", gender_options[0])
gender_options[0].click()
place_options = room.find_elements(By.CSS_SELECTOR, "div.AB7Lab.Id5V1")
driver.execute_script("arguments[0].disabled=false", place_options[0])
place_options[0].click()
html = driver.find_element(By.TAG_NAME, "html")
html.send_keys(Keys.END)
break
@jin-park
Copy link
Author

jin-park commented Apr 2, 2023

For HAFS students!

INSTRUCTIONS:

  1. Install software related to selenium and chrome webdrivers
  2. Replace the part inside quotes with your name and student id
  3. Replace the index of place_options with the one you're trying to reserve (e.g. 0 for the first location on the google form)
  4. Download and run the program using Python: python automate.py (this will open chrome)
  5. Go to accounts.google.com and log into your google account
  6. Go to the google form URL
  7. The form will fill up automatically!...(if it works)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment