session.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. global URL
  10. global whoHereFor
  11. # path to chromedriver
  12. # DRIVER_PATH = "/home/michtang/selenium/chromedriver"
  13. DRIVER_PATH = "/Users/michaeltang/Documents/selenium/chromedriver_mac"
  14. driver = webdriver.Chrome(DRIVER_PATH)
  15. def checkIn():
  16. ############### Start of check In #################
  17. textboxes = driver.find_elements_by_class_name("quantumWizTextinputPaperinputInput")
  18. textboxes[0].send_keys("Michael Tang")
  19. checkInRadio = driver.find_element_by_css_selector("#i9")
  20. checkInRadio.click()
  21. nextButton = driver.find_element_by_class_name("quantumWizButtonPaperbuttonLabel")
  22. nextButton.click()
  23. time.sleep(2)
  24. # check In
  25. # get textboxes
  26. textboxes2 = driver.find_elements_by_class_name("quantumWizTextinputPaperinputInput")
  27. # get radio buttons
  28. radiobuttons = driver.find_elements_by_class_name("docssharedWizToggleLabeledLabelWrapper")
  29. # get submit button
  30. buttons = driver.find_elements_by_class_name("quantumWizButtonPaperbuttonLabel")
  31. # email [0]
  32. textboxes2[0].send_keys("michael.tang@epsb.ca")
  33. # org [1]
  34. textboxes2[1].send_keys("EPS Supply Services")
  35. # phone number [2]
  36. textboxes2[2].send_keys("7809656618")
  37. # who will you be working with [3]
  38. textboxes2[3].send_keys(whoHereFor)
  39. # click no radio
  40. radiobuttons[0].click()
  41. # click next
  42. buttons[1].click()
  43. print('waiting 2 seconds for final page to load')
  44. time.sleep(2)
  45. buttons = driver.find_elements_by_class_name("quantumWizButtonPaperbuttonLabel")
  46. # find the submit button
  47. buttonText = buttons[1].text
  48. pressSubmit = input("Press submit? (y/n)")
  49. if pressSubmit == "y":
  50. print(buttons[1].text)
  51. buttons[1].click()
  52. time.sleep(1)
  53. print("quitting")
  54. driver.quit()
  55. elif pressSubmit == "n":
  56. print("Manual mode")
  57. buttons[0].click()
  58. else:
  59. print("invalid key pressed.")
  60. ########################## end of Check in ###########################
  61. def checkOut():
  62. ############################ start Check Out ############################
  63. textboxes = driver.find_elements_by_class_name("quantumWizTextinputPaperinputInput")
  64. textboxes[0].send_keys("Michael Tang")
  65. checkOutRadio = driver.find_element_by_css_selector("#i12")
  66. checkOutRadio.click()
  67. nextButton = driver.find_element_by_css_selector(".quantumWizButtonPaperbuttonLabel")
  68. nextButton.click()
  69. time.sleep(3) # wait for next page to load
  70. # Next page of check Out
  71. whoWereYouHereFor = driver.find_element_by_css_selector(".exportTextarea")
  72. whoWereYouHereFor.send_keys(whoHereFor)
  73. # Automated click of submit
  74. buttons = driver.find_elements_by_class_name("quantumWizButtonPaperbuttonLabel")
  75. # find the submit button
  76. buttonText = buttons[1].text
  77. pressSubmit = input("Press submit? (y/n)")
  78. if pressSubmit == "y":
  79. print(buttons[1].text)
  80. buttons[1].click()
  81. time.sleep(1)
  82. print("quitting")
  83. driver.quit()
  84. elif pressSubmit == "n":
  85. print("Manual mode")
  86. buttons[0].click()
  87. else:
  88. print("invalid key pressed.")
  89. ############################ end Check Out ##############################
  90. def locationSelector():
  91. print("Select the school: ")
  92. print("1. ABM")
  93. print("2. DTK")
  94. print("3. LOHS")
  95. print("4. GHL")
  96. print("5. DDM")
  97. schoolSelected = input("Select the school: ")
  98. if schoolSelected == "1":
  99. global URL
  100. URL = "https://docs.google.com/forms/d/e/1FAIpQLSeJf3A_bADAUyaXuTEfiyU5O4V77PxcL9lYBSC3vgP4Fn4eGg/viewform"
  101. elif schoolSelected == "2":
  102. URL = "https://docs.google.com/forms/d/e/1FAIpQLSfIZdJoeB8MUrUSAsbKkgsrsRbXB0nUYui2Dn2weCfa5l_KIw/viewform"
  103. elif schoolSelected == "3":
  104. URL = "https://docs.google.com/forms/d/e/1FAIpQLSeACzhxKn6mVV0ArePRXE1qz_uojT9CT53OaXnYpEh7T4GzJg/viewform"
  105. elif schoolSelected == "4":
  106. URL = "https://docs.google.com/forms/d/e/1FAIpQLSdIT2XbkW4leXrQmS0rEuQ70lZoXkNG_zv7a0JOIRS4wuyxfw/viewform"
  107. elif schoolSelected == "5":
  108. URL = "https://docs.google.com/forms/d/e/1FAIpQLSeQJO4uzCHg-OIawaWiVcjJrhcVsFKZ-2hDF4wOaDmz9Xx86w/viewform"
  109. else:
  110. print("not a valid selection.")
  111. locationSelector()
  112. def main():
  113. locationSelector()
  114. # executor_url = driver.command_executor._url
  115. # session_id = driver.session_id
  116. # print(session_id)
  117. driver.get(URL)
  118. # time.sleep(2)
  119. print("Enter what you want to do: ")
  120. print("1: check in")
  121. print("2. check out")
  122. checkInOut = input("Your selection: ")
  123. # print(checkInOut)
  124. if checkInOut == "1":
  125. print("running check in")
  126. global whoHereFor
  127. whoHereFor = input("Who are you in for: ")
  128. checkIn()
  129. elif checkInOut == "2":
  130. print("running check out")
  131. whoHereFor = input("Who were you in for: ")
  132. checkOut()
  133. else:
  134. print("you did not enter a valid option")
  135. main()
  136. # execute main function
  137. main()