소스 검색

Add Exception handling for cases where textbox for who you were in for doesn't exist

Michael Tang 4 년 전
부모
커밋
90bb25fb41
1개의 변경된 파일25개의 추가작업 그리고 20개의 파일을 삭제
  1. 25 20
      session.py

+ 25 - 20
session.py

@@ -6,13 +6,14 @@ date modified: 2021-02-07
 '''
 import time
 from selenium import webdriver
+from selenium.common.exceptions import NoSuchElementException
 
 global URL
 global whoHereFor
 
 # path to chromedriver
 # DRIVER_PATH = "/home/michtang/selenium/chromedriver"
-DRIVER_PATH = "/Users/michaeltang/Documents/selenium/chromedriver_mac" 
+DRIVER_PATH = "/Users/michaeltang/Documents/selenium/chromedriver" 
 driver = webdriver.Chrome(DRIVER_PATH)
 
 def checkIn():
@@ -81,26 +82,27 @@ def checkOut():
     nextButton.click()
     time.sleep(3) # wait for next page to load
     # Next page of check Out
-
-    whoWereYouHereFor = driver.find_element_by_css_selector(".exportTextarea")
-    whoWereYouHereFor.send_keys(whoHereFor)
-
+    try:
+        whoWereYouHereFor = driver.find_element_by_css_selector(".exportTextarea")
+        whoWereYouHereFor.send_keys(whoHereFor)
+    except NoSuchElementException:
+        print("no text area to enter")
     # Automated click of submit
-    buttons =  driver.find_elements_by_class_name("quantumWizButtonPaperbuttonLabel")
+        buttons =  driver.find_elements_by_class_name("quantumWizButtonPaperbuttonLabel")
     # find the submit button 
-    buttonText = buttons[1].text
-    pressSubmit = input("Press submit? (y/n)")
-    if pressSubmit == "y":
-        print(buttons[1].text)
-        buttons[1].click()
-        time.sleep(1)
-        print("quitting")
-        driver.quit()
-    elif pressSubmit == "n":
-        print("Manual mode")
-        buttons[0].click()
-    else:
-        print("invalid key pressed.")
+        buttonText = buttons[1].text
+        pressSubmit = input("Press submit? (y/n)")
+        if pressSubmit == "y":
+            print(buttons[1].text)
+            buttons[1].click()
+            time.sleep(1)
+            print("quitting")
+            driver.quit()
+        elif pressSubmit == "n":
+            print("Manual mode")
+            buttons[0].click()
+        else:
+            print("invalid key pressed.")
     ############################ end Check Out ##############################
 
 def locationSelector():
@@ -111,6 +113,7 @@ def locationSelector():
     print("4. GHL")
     print("5. DDM")
     print("6. McNally")
+    print("7. DAA")
     schoolSelected = input("Select the school: ")
     if schoolSelected == "1":
         global URL
@@ -125,6 +128,8 @@ def locationSelector():
         URL = "https://docs.google.com/forms/d/e/1FAIpQLSeQJO4uzCHg-OIawaWiVcjJrhcVsFKZ-2hDF4wOaDmz9Xx86w/viewform"
     elif schoolSelected == "6":
         URL = "https://docs.google.com/forms/d/e/1FAIpQLSe8faJgWiVMym4pw6VNR5aJ7j9cJUkP2TYSNUIrYnAcJyaD2w/viewform"
+    elif schoolSelected == "7":
+        URL = "https://docs.google.com/forms/d/e/1FAIpQLSftjfI8mR3fF8IlnRnBiD5w8rbP1Q10hd_sL7vv1zd_qU50iQ/viewform?fbzx=-2834371413822588919"
     else:
         print("not a valid selection.")
         locationSelector()
@@ -147,7 +152,7 @@ def main():
         whoHereFor = input("Who are you in for: ")
         checkIn()
     elif checkInOut == "2":
-        print("running check out")
+        print("running check out") 
         whoHereFor = input("Who were you in for: ")
         checkOut()
     else: