session.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. '''
  2. title: Automated EPSB check in/out script
  3. author: michael Tang
  4. date created: 2021-01-25
  5. date modified: 2021-02-07
  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_class_name("quantumWizTextinputPaperinputInput")
  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("quantumWizButtonPaperbuttonLabel")
  23. nextButton.click()
  24. time.sleep(2)
  25. # check In
  26. # get textboxes
  27. textboxes2 = driver.find_elements_by_class_name("quantumWizTextinputPaperinputInput")
  28. # get radio buttons
  29. radiobuttons = driver.find_elements_by_class_name("docssharedWizToggleLabeledLabelWrapper")
  30. # get submit button
  31. buttons = driver.find_elements_by_class_name("quantumWizButtonPaperbuttonLabel")
  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_class_name("quantumWizButtonPaperbuttonLabel")
  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)
  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. else:
  60. print("invalid key pressed.")
  61. ########################## end of Check in ###########################
  62. def checkOut():
  63. ############################ start Check Out ############################
  64. textboxes = driver.find_elements_by_class_name("quantumWizTextinputPaperinputInput")
  65. textboxes[0].send_keys("Michael Tang")
  66. checkOutRadio = driver.find_element_by_css_selector("#i12")
  67. checkOutRadio.click()
  68. nextButton = driver.find_element_by_css_selector(".quantumWizButtonPaperbuttonLabel")
  69. nextButton.click()
  70. time.sleep(3) # wait for next page to load
  71. # Next page of check Out
  72. try:
  73. whoWereYouHereFor = driver.find_element_by_css_selector(".exportTextarea")
  74. whoWereYouHereFor.send_keys(whoHereFor)
  75. except NoSuchElementException:
  76. print("no text area to enter")
  77. # Automated click of submit
  78. buttons = driver.find_elements_by_class_name("quantumWizButtonPaperbuttonLabel")
  79. # find the submit button
  80. buttonText = buttons[1].text
  81. pressSubmit = input("Press submit? (y/n)")
  82. if pressSubmit == "y":
  83. print(buttons[1].text)
  84. buttons[1].click()
  85. time.sleep(1)
  86. print("quitting")
  87. driver.quit()
  88. elif pressSubmit == "n":
  89. print("Manual mode")
  90. buttons[0].click()
  91. else:
  92. print("invalid key pressed.")
  93. ############################ end Check Out ##############################
  94. def locationSelector():
  95. print("Select the school: ")
  96. print("1. ABM")
  97. print("2. DTK")
  98. print("3. LOHS")
  99. print("4. GHL")
  100. print("5. DDM")
  101. print("6. McNally")
  102. print("7. DAA")
  103. schoolSelected = input("Select the school: ")
  104. if schoolSelected == "1":
  105. global URL
  106. URL = "https://docs.google.com/forms/d/e/1FAIpQLSeJf3A_bADAUyaXuTEfiyU5O4V77PxcL9lYBSC3vgP4Fn4eGg/viewform"
  107. elif schoolSelected == "2":
  108. URL = "https://docs.google.com/forms/d/e/1FAIpQLSfIZdJoeB8MUrUSAsbKkgsrsRbXB0nUYui2Dn2weCfa5l_KIw/viewform"
  109. elif schoolSelected == "3":
  110. URL = "https://docs.google.com/forms/d/e/1FAIpQLSeACzhxKn6mVV0ArePRXE1qz_uojT9CT53OaXnYpEh7T4GzJg/viewform"
  111. elif schoolSelected == "4":
  112. URL = "https://docs.google.com/forms/d/e/1FAIpQLSdIT2XbkW4leXrQmS0rEuQ70lZoXkNG_zv7a0JOIRS4wuyxfw/viewform"
  113. elif schoolSelected == "5":
  114. URL = "https://docs.google.com/forms/d/e/1FAIpQLSeQJO4uzCHg-OIawaWiVcjJrhcVsFKZ-2hDF4wOaDmz9Xx86w/viewform"
  115. elif schoolSelected == "6":
  116. URL = "https://docs.google.com/forms/d/e/1FAIpQLSe8faJgWiVMym4pw6VNR5aJ7j9cJUkP2TYSNUIrYnAcJyaD2w/viewform"
  117. elif schoolSelected == "7":
  118. URL = "https://docs.google.com/forms/d/e/1FAIpQLSftjfI8mR3fF8IlnRnBiD5w8rbP1Q10hd_sL7vv1zd_qU50iQ/viewform?fbzx=-2834371413822588919"
  119. else:
  120. print("not a valid selection.")
  121. locationSelector()
  122. def main():
  123. locationSelector()
  124. # executor_url = driver.command_executor._url
  125. # session_id = driver.session_id
  126. # print(session_id)
  127. driver.get(URL)
  128. # time.sleep(2)
  129. print("Enter what you want to do: ")
  130. print("1: check in")
  131. print("2. check out")
  132. checkInOut = input("Your selection: ")
  133. # print(checkInOut)
  134. if checkInOut == "1":
  135. print("running check in")
  136. global whoHereFor
  137. whoHereFor = input("Who are you in for: ")
  138. checkIn()
  139. elif checkInOut == "2":
  140. print("running check out")
  141. whoHereFor = input("Who were you in for: ")
  142. checkOut()
  143. else:
  144. print("you did not enter a valid option")
  145. main()
  146. # execute main function
  147. main()