session.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. elif pressSubmit == "n":
  52. print("Manual mode")
  53. buttons[0].click()
  54. else:
  55. print("invalid key pressed.")
  56. ########################## end of Check in ###########################
  57. def checkOut():
  58. ############################ start Check Out ############################
  59. textboxes = driver.find_elements_by_class_name("quantumWizTextinputPaperinputInput")
  60. textboxes[0].send_keys("Michael Tang")
  61. checkOutRadio = driver.find_element_by_css_selector("#i12")
  62. checkOutRadio.click()
  63. nextButton = driver.find_element_by_css_selector(".quantumWizButtonPaperbuttonLabel")
  64. nextButton.click()
  65. time.sleep(3) # wait for next page to load
  66. # Next page of check Out
  67. whoWereYouHereFor = driver.find_element_by_css_selector(".exportTextarea")
  68. whoWereYouHereFor.send_keys(whoHereFor)
  69. ############################ end Check Out ##############################
  70. def locationSelector():
  71. print("Select the school: ")
  72. print("1. ABM")
  73. schoolSelected = input("Select the school: ")
  74. if schoolSelected == "1":
  75. global URL
  76. URL = "https://docs.google.com/forms/d/e/1FAIpQLSeJf3A_bADAUyaXuTEfiyU5O4V77PxcL9lYBSC3vgP4Fn4eGg/viewform"
  77. else:
  78. print("not a valid selection.")
  79. locationSelector()
  80. def main():
  81. locationSelector()
  82. # executor_url = driver.command_executor._url
  83. # session_id = driver.session_id
  84. # print(session_id)
  85. driver.get(URL)
  86. # time.sleep(2)
  87. print("Enter what you want to do: ")
  88. print("1: check in")
  89. print("2. check out")
  90. checkInOut = input("Your selection: ")
  91. # print(checkInOut)
  92. if checkInOut == "1":
  93. print("running check in")
  94. global whoHereFor
  95. whoHereFor = input("Who are you in for: ")
  96. checkIn()
  97. elif checkInOut == "2":
  98. print("running check out")
  99. whoHereFor = input("Who were you in for: ")
  100. checkOut()
  101. else:
  102. print("you did not enter a valid option")
  103. main()
  104. # execute main function
  105. main()