Trying to build a simple reservation script that chooses 3 days ahead, selects a time, chooses next, and then click finalizes reservation. The script is below:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import time
chromedriver_path = '/Users/stevenlang/Documents/chromedriver'
options = Options()
options.page_load_strategy = 'normal' # Can try 'eager' or 'none'
driver = webdriver.Chrome(options=options)
service = Service(executable_path=chromedriver_path)
driver = webdriver.Chrome(service=service)
driver.get('https://golfburnaby.cps.golf/onlineresweb/auth/verify-email')
time.sleep(1)
email_input = driver.find_element(By.ID, "mat-input-0")
email_input.send_keys("RANDOM NUMBER")
email_input.send_keys(Keys.RETURN)
time.sleep(1)
password_input = driver.find_element(By.ID, "mat-input-1")
password_input.send_keys("RANDOM PASSWORD")
password_input.send_keys(Keys.RETURN)
time.sleep(1)
input_element = driver.find_element(By.CLASS_NAME, "right-chevron-button")
input_element.click()
time.sleep(1)
input_element = driver.find_element(By.CLASS_NAME, "right-chevron-button")
input_element.click()
time.sleep(1)
input_element = driver.find_element(By.CLASS_NAME, "right-chevron-button")
input_element.click()
time.sleep(1)
tee_time_elements = driver.find_elements(By.CLASS_NAME, "teetimetableDateTime")
for element in tee_time_elements:
if element.text == "5:09 PM":
booking_button = element.find_element(By.XPATH, "./ancestor::button")
break
booking_button.click()
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[.//span[contains(@class, 'mat-button-wrapper') and contains(text(), 'Next')]]"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[.//span[contains(text(), 'Finalize Reservation')]]"))).click()
The issue is that the script breaks down on the 2nd part (after the booking_button.click()) It runs separately as in if I only run the first part it works and then after only run the 2nd part it also works but I cannot get it to run together.
I've never done any coding or doing anything like this in general and it's destroying my mental health.
It runs separately but not together