session.py 5.0 KB

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