session.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. '''
  2. title: Automated EPSB check in/out script
  3. author: michael Tang
  4. date created: 2021-01-25
  5. date modified: 2021-02-01
  6. '''
  7. import time
  8. from selenium import webdriver
  9. global URL
  10. global whoHereFor
  11. def checkIn():
  12. ############### Start of check In #################
  13. textboxes = driver.find_elements_by_class_name("quantumWizTextinputPaperinputInput")
  14. textboxes[0].send_keys("Michael Tang")
  15. checkInRadio = driver.find_element_by_css_selector("#i9")
  16. checkInRadio.click()
  17. nextButton = driver.find_element_by_class_name("quantumWizButtonPaperbuttonLabel")
  18. nextButton.click()
  19. time.sleep(2)
  20. # check In
  21. # get textboxes
  22. textboxes2 = driver.find_elements_by_class_name("quantumWizTextinputPaperinputInput")
  23. # get radio buttons
  24. radiobuttons = driver.find_elements_by_class_name("docssharedWizToggleLabeledLabelWrapper")
  25. # get submit button
  26. buttons = driver.find_elements_by_class_name("quantumWizButtonPaperbuttonLabel")
  27. # email [0]
  28. textboxes2[0].send_keys("michael.tang@epsb.ca")
  29. # org [1]
  30. textboxes2[1].send_keys("EPS Supply Services")
  31. # phone number [2]
  32. textboxes2[2].send_keys("7809656618")
  33. # who will you be working with [3]
  34. textboxes2[3].send_keys(whoHereFor)
  35. # click no radio
  36. radiobuttons[0].click()
  37. # click next
  38. buttons[1].click()
  39. print('waiting 2 seconds for final page to load')
  40. time.sleep(2)
  41. buttons = driver.find_elements_by_class_name("quantumWizButtonPaperbuttonLabel")
  42. # find the submit button
  43. buttonText = buttons[1].text
  44. pressSubmit = input("Press submit? (y/n)")
  45. if pressSubmit == "y":
  46. print(buttons[1].text)
  47. buttons[1].click()
  48. elif pressSubmit == "n":
  49. print("done")
  50. else:
  51. print("invalid key pressed.")
  52. ########################## end of Check in ###########################
  53. def checkOut():
  54. ############################ start Check Out ############################
  55. textboxes = driver.find_elements_by_class_name("quantumWizTextinputPaperinputInput")
  56. textboxes[0].send_keys("Michael Tang")
  57. checkOutRadio = driver.find_element_by_css_selector("#i12")
  58. checkOutRadio.click()
  59. nextButton = driver.find_element_by_css_selector(".quantumWizButtonPaperbuttonLabel")
  60. nextButton.click()
  61. time.sleep(3) # wait for next page to load
  62. # Next page of check Out
  63. whoWereYouHereFor = driver.find_element_by_css_selector(".exportTextarea")
  64. whoWereYouHereFor.send_keys(whoHereFor)
  65. ############################ end Check Out ##############################
  66. def locationSelector():
  67. print("Select the school: ")
  68. print("1. ABM")
  69. schoolSelected = input("Select the school: ")
  70. if schoolSelected == "1":
  71. global URL
  72. URL = "https://docs.google.com/forms/d/e/1FAIpQLSeJf3A_bADAUyaXuTEfiyU5O4V77PxcL9lYBSC3vgP4Fn4eGg/viewform"
  73. else:
  74. print("not a valid selection.")
  75. DRIVER_PATH = "/home/michtang/selenium/chromedriver"
  76. # URL = input("Enter the URL: ")
  77. locationSelector()
  78. driver = webdriver.Chrome(DRIVER_PATH)
  79. executor_url = driver.command_executor._url
  80. session_id = driver.session_id
  81. print(session_id)
  82. driver.get(URL)
  83. time.sleep(3)
  84. print("Enter what you want to do: ")
  85. print("1: check in")
  86. print("2. check out")
  87. checkInOut = input("Your selection: ")
  88. # print(checkInOut)
  89. if checkInOut == "1":
  90. print("running check in")
  91. global whoHereFor
  92. whoHereFor = input("Who are you in for: ")
  93. checkIn()
  94. elif checkInOut == "2":
  95. print("running check out")
  96. whoHereFor = input("Who were you in for: ")
  97. checkOut()
  98. else:
  99. print("you did not enter a valid option")