import time
from selenium import webdriver
from bs4 import BeautifulSoup

DRIVER_PATH = "/Users/michaeltang/.wdm/drivers/chromedriver/88.0.4324.96/mac64/chromedriver"
URL = "https://epsb.eschoolsolutions.com/substituteAvailableJobAction.do"



# This loads webdriver from the local machine if it exists.
browser =  webdriver.Chrome(DRIVER_PATH)
browser.get(URL)

# Give the browser time to load all content.
userId = browser.find_element_by_css_selector("#userId")
userId.send_keys("9656618")
userPin = browser.find_element_by_css_selector("#userPin")
userPin.send_keys("nCytosub7410")
loginButton = browser.find_element_by_css_selector("#submitBtn")
loginButton.click()

logged_in = False

while not logged_in:
    try:
        availableJobsSelector = browser.find_element_by_css_selector("#sidious\.menu\.title\.AvailableJobs")
        availableJobsSelector.click()
    except:
        print("Not logged in yet! Waiting 5 seconds...")
        time.sleep(1)
    else:
        print("Successfully logged in!")
        logged_in = True
#availableJobsSelector.click()
time.sleep(2)
endDatePicker = browser.find_element_by_css_selector("#endDate")
endDatePicker.clear()
endDatePicker.send_keys("06/30/2021")
search = browser.find_element_by_css_selector(".submitButton")
search.click()
