session.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. '''
  2. title: Automated EPSB check in/out script
  3. author: michael Tang
  4. date created: 2021-01-25
  5. date modified: 2022-03-03
  6. '''
  7. import time
  8. from selenium import webdriver
  9. from selenium.common.exceptions import NoSuchElementException
  10. global URL
  11. global whoHereFor
  12. # path to chromedriver
  13. # DRIVER_PATH = "/home/michtang/selenium/chromedriver"
  14. DRIVER_PATH = "/Users/michaeltang/Documents/selenium/chromedriver"
  15. driver = webdriver.Chrome(DRIVER_PATH)
  16. def checkIn():
  17. ############### Start of check In #################
  18. textboxes = driver.find_elements_by_xpath("//input[@class='whsOnd zHQkBf']")
  19. textboxes[0].send_keys("Michael Tang")
  20. checkInRadio = driver.find_element_by_css_selector("#i9")
  21. checkInRadio.click()
  22. nextButton = driver.find_element_by_class_name("uArJ5e")
  23. nextButton.click()
  24. time.sleep(2)
  25. # check In
  26. # get textboxes
  27. textboxes2 = driver.find_elements_by_xpath("//input[@class='whsOnd zHQkBf']")
  28. # get radio buttons
  29. radiobuttons = driver.find_elements_by_id("i21")
  30. # get submit button
  31. buttons = driver.find_elements_by_xpath("//div[@class='uArJ5e UQuaGc YhQJj zo8FOc IT3Lge']")
  32. # email [0]
  33. textboxes2[0].send_keys("michael.tang@epsb.ca")
  34. # org [1]
  35. textboxes2[1].send_keys("EPS Supply Services")
  36. # phone number [2]
  37. textboxes2[2].send_keys("7809656618")
  38. # who will you be working with [3]
  39. textboxes2[3].send_keys(whoHereFor)
  40. # click no radio
  41. radiobuttons[0].click()
  42. # click next
  43. buttons[1].click()
  44. print('waiting 2 seconds for final page to load')
  45. time.sleep(2)
  46. buttons = driver.find_elements_by_xpath("//div[@role='button']")
  47. # find the submit button
  48. #buttonText = buttons[1].text
  49. pressSubmit = input("Press submit? (y/n)")
  50. if pressSubmit == "y":
  51. print(buttons[1].text+" clicked!")
  52. buttons[1].click()
  53. time.sleep(1)
  54. print("quitting")
  55. driver.quit()
  56. elif pressSubmit == "n":
  57. print("Manual mode")
  58. #buttons[0].click()
  59. #find back button
  60. backButton = driver.find_element_by_xpath("//div[@class='uArJ5e UQuaGc YhQJj zo8FOc IT3Lge']")
  61. print(backButton.text + " clicked.")
  62. buttons[0].click()
  63. else:
  64. print("invalid key pressed.")
  65. ########################## end of Check in ##############################
  66. def checkOut():
  67. ############################ start Check Out ############################
  68. textboxes = driver.find_elements_by_xpath("//input[@class='whsOnd zHQkBf']")
  69. textboxes[0].send_keys("Michael Tang")
  70. checkOutRadio = driver.find_element_by_css_selector("#i12")
  71. try:
  72. checkOutRadio.click()
  73. except:
  74. print("exception")
  75. nextButton = driver.find_element_by_class_name("uArJ5e")
  76. nextButton.click()
  77. time.sleep(3) # wait for next page to load
  78. # Next page of check Out
  79. try:
  80. whoWereYouHereFor = driver.find_element_by_xpath("//textarea[@class='KHxj8b tL9Q4c']")
  81. whoWereYouHereFor.click()
  82. whoWereYouHereFor.send_keys(whoHereFor)
  83. except NoSuchElementException:
  84. print("no text area to enter")
  85. # Automated click of submit
  86. submitButton = driver.find_elements_by_xpath("//div[@role='button']")
  87. # find the submit button
  88. buttonText = submitButton[1].text
  89. pressSubmit = input("Press submit? (y/n)")
  90. if pressSubmit == "y":
  91. print(buttonText + " clicked!")
  92. submitButton[0].click()
  93. time.sleep(1)
  94. print("quitting")
  95. driver.quit()
  96. elif pressSubmit == "n":
  97. print("Manual mode engaged.")
  98. # find the back button
  99. backButton = driver.find_elements_by_xpath("//div[@role='button']")
  100. print(backButton[0].text+ " clicked!")
  101. backButton[0].click()
  102. else:
  103. print("invalid key pressed.")
  104. ############################ end Check Out ##############################
  105. def locationSelector():
  106. print("Select the school: ")
  107. print("1. ABM")
  108. print("2. DTK")
  109. print("3. LOHS")
  110. print("4. GHL")
  111. print("5. DDM")
  112. print("6. McNally")
  113. print("7. DAA")
  114. print("8. Victoria")
  115. schoolSelected = input("Select the school: ")
  116. if schoolSelected == "1":
  117. global URL
  118. URL = "https://docs.google.com/forms/d/e/1FAIpQLSeJf3A_bADAUyaXuTEfiyU5O4V77PxcL9lYBSC3vgP4Fn4eGg/viewform"
  119. elif schoolSelected == "2":
  120. URL = "https://docs.google.com/forms/d/e/1FAIpQLSfIZdJoeB8MUrUSAsbKkgsrsRbXB0nUYui2Dn2weCfa5l_KIw/viewform"
  121. elif schoolSelected == "3":
  122. URL = "https://docs.google.com/forms/d/e/1FAIpQLSeACzhxKn6mVV0ArePRXE1qz_uojT9CT53OaXnYpEh7T4GzJg/viewform"
  123. elif schoolSelected == "4":
  124. URL = "https://docs.google.com/forms/d/e/1FAIpQLSdIT2XbkW4leXrQmS0rEuQ70lZoXkNG_zv7a0JOIRS4wuyxfw/viewform"
  125. elif schoolSelected == "5":
  126. URL = "https://docs.google.com/forms/d/e/1FAIpQLSeQJO4uzCHg-OIawaWiVcjJrhcVsFKZ-2hDF4wOaDmz9Xx86w/viewform"
  127. elif schoolSelected == "6":
  128. URL = "https://docs.google.com/forms/d/e/1FAIpQLSe8faJgWiVMym4pw6VNR5aJ7j9cJUkP2TYSNUIrYnAcJyaD2w/viewform"
  129. elif schoolSelected == "7":
  130. URL = "https://docs.google.com/forms/d/e/1FAIpQLSftjfI8mR3fF8IlnRnBiD5w8rbP1Q10hd_sL7vv1zd_qU50iQ/viewform?fbzx=-2834371413822588919"
  131. elif schoolSelected == "8":
  132. URL = "https://docs.google.com/forms/d/e/1FAIpQLSdviM6-Ua5yQvYAGLfBXeMN7w3SjHAcQPB9d29fZEettwWHlQ/viewform"
  133. else:
  134. print("not a valid selection.")
  135. locationSelector()
  136. def main():
  137. locationSelector()
  138. # executor_url = driver.command_executor._url
  139. # session_id = driver.session_id
  140. # print(session_id)
  141. driver.get(URL)
  142. # time.sleep(2)
  143. print("Enter what you want to do: ")
  144. print("1: check in")
  145. print("2. check out")
  146. checkInOut = input("Your selection: ")
  147. # print(checkInOut)
  148. if checkInOut == "1":
  149. print("running check in")
  150. global whoHereFor
  151. whoHereFor = input("Who are you in for: ")
  152. checkIn()
  153. elif checkInOut == "2":
  154. print("running check out")
  155. whoHereFor = input("Who were you in for: ")
  156. checkOut()
  157. else:
  158. print("you did not enter a valid option")
  159. main()
  160. # execute main function
  161. main()