-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoSelect.py
More file actions
171 lines (141 loc) · 5.08 KB
/
autoSelect.py
File metadata and controls
171 lines (141 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import emailer as mail
from webdriver_manager.chrome import ChromeDriverManager
# Input login
username = ""
password = ""
# Enter first CRN Schedule
CRN1 = "21857"
CRN2 = ""
CRN3 = ""
CRN4 = ""
CRN5 = ""
CRN6 = ""
# Enter seceond set
second_CRN1 = "21857"
second_CRN2 = ""
second_CRN3 = ""
second_CRN4 = ""
second_CRN5 = ""
second_CRN6 = ""
# Enter 3rd schedule is applicable
third_CRN1 = ""
third_CRN2 = ""
third_CRN3 = ""
third_CRN4 = ""
third_CRN5 = ""
third_CRN6 = ""
#Initialize counter variables
schedule1 = 1
schedule2 = 1
schedule3=1
#Create driver
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(ChromeDriverManager().install(),chrome_options=chrome_options)
#navigate to leopardweb
driver.get("https://leopardweb.wit.edu")
#Startup console message
print("Headless Driver Started")
# Find username and enter username
id_box = driver.find_element_by_name('username')
id_box.send_keys(username)
# Find password and enter password
pass_box = driver.find_element_by_name('password')
pass_box.send_keys(password)
# Submit password
login_button = driver.find_element_by_name('submit').click()
# Navigate to student
student_button = driver.find_element_by_link_text('Student').click()
# Navigate to registration
schedstudent_button = driver.find_element_by_link_text('Registration').click()
# Navigate to select term
sub_button = driver.find_element_by_link_text('Select Term').click()
# Submit select term option
button_button = driver.find_element_by_xpath("/html/body/div[3]/form/input[2]").click()
# Navigate to Add Drop
student_button = driver.find_element_by_link_text('Add or Drop Classes').click()
#Loop to find first schedule
while schedule1 <= 3:
# Enter CRN numbers, adjust keys accordingly
id_box = driver.find_element_by_id("crn_id1")
id_box.send_keys(CRN1)
id_box = driver.find_element_by_id("crn_id2")
id_box.send_keys(CRN2)
id_box = driver.find_element_by_id("crn_id3")
id_box.send_keys(CRN3)
id_box = driver.find_element_by_id("crn_id4")
id_box.send_keys(CRN4)
id_box = driver.find_element_by_id("crn_id5")
id_box.send_keys(CRN5)
id_box = driver.find_element_by_id("crn_id6")
id_box.send_keys(CRN6)
# Final submit classes
submit_changes = driver.find_element_by_xpath("/html/body/div[3]/form/input[19]").click()
if driver.page_source.find("Registration Add Errors"):
schedule1 = schedule1 + 1
print("Schedule 1 has failed")
else:
print("Schedule 1 was successful!")
break
if schedule1 >= 3:
print("Schedule 1 has failed to many times moving onto schedule 2:")
while schedule2 <= 3:
# Enter CRN numbers, adjust keys accordingly
id_box = driver.find_element_by_id("crn_id1")
id_box.send_keys(second_CRN1)
id_box = driver.find_element_by_id("crn_id2")
id_box.send_keys(second_CRN2)
id_box = driver.find_element_by_id("crn_id3")
id_box.send_keys(second_CRN3)
id_box = driver.find_element_by_id("crn_id4")
id_box.send_keys(second_CRN4)
id_box = driver.find_element_by_id("crn_id5")
id_box.send_keys(second_CRN5)
id_box = driver.find_element_by_id("crn_id6")
id_box.send_keys(second_CRN6)
submit_changes = driver.find_element_by_xpath("/html/body/div[3]/form/input[19]").click()
if driver.page_source.find("Registration Add Errors"):
schedule2 = schedule2 + 1
print("Schedule 2 has failed")
else:
break
if schedule2 >= 3:
print("Schedule 2 has failed to many times moving onto schedule 3:")
while schedule3 <= 3:
# Enter CRN numbers, adjust keys accordingly
id_box = driver.find_element_by_id("crn_id1")
id_box.send_keys(third_CRN1)
id_box = driver.find_element_by_id("crn_id2")
id_box.send_keys(third_CRN2)
id_box = driver.find_element_by_id("crn_id3")
id_box.send_keys(third_CRN3)
id_box = driver.find_element_by_id("crn_id4")
id_box.send_keys(third_CRN4)
id_box = driver.find_element_by_id("crn_id5")
id_box.send_keys(third_CRN5)
id_box = driver.find_element_by_id("crn_id6")
id_box.send_keys(third_CRN6)
submit_changes = driver.find_element_by_xpath("/html/body/div[3]/form/input[19]").click()
if driver.page_source.find("Registration Add Errors"):
schedule3 = schedule3 + 1
print("Schedule 3 has failed")
else:
break
if schedule3 >= 3:
print("ERROR: All schedules have failed, Sending warning email")
mail.failure()
else:
print("Schedule 3 has succeeded")
mail.success()
else:
print("Program has suceeded")
mail.success()
else:
print("Program has succeeded")
mail.success()
driver.close()
driver.quit()