-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBot.py
232 lines (213 loc) · 7.87 KB
/
Bot.py
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
from selenium import webdriver
import time
from config import *
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def customPrint(text, texttype="MESSAGE"):
if texttype == "WARNING":
print(f"{WARNING}${texttype}: {text}{ENDC}")
elif texttype == "SUCCESS":
print(f"{OKGREEN}${texttype}: {text}{ENDC}")
elif texttype == "INFO":
print(f"{OKCYAN}${texttype}: {text}{ENDC}")
elif texttype == "ERROR":
print(f"{FAIL}${texttype}: {text}{ENDC}")
elif texttype == "MESSAGE":
print(f"{OKBLUE}${texttype}: {text}{ENDC}")
else:
print(f"{FAIL}{text}{ENDC}")
class Bot:
def __init__(self):
self.driver = webdriver.Chrome(executable_path=DRIVER_PATH)
self.driver.get(
"https://myacademy.oracle.com/lmt/xlr8login.login?site=oa")
self.parent_handle = self.driver.current_window_handle
def login(self):
customPrint("Filling Username", "INFO")
# fill username
while True:
try:
self.driver.find_element_by_id(
"inputUsername").send_keys(USERNAME)
break
except:
time.sleep(TIMEOUT)
customPrint("Filled Username", "INFO")
customPrint("Filling Password", "INFO")
# fill password
while True:
try:
self.driver.find_element_by_id(
"inputPassword").send_keys(PASSWORD)
break
except:
time.sleep(TIMEOUT)
customPrint("Filled Password", "INFO")
# click on signin
while True:
try:
self.driver.find_element_by_class_name(
"primary.btn.login").click()
break
except:
time.sleep(TIMEOUT)
customPrint("Next", "SUCCESS")
return True
def openChannel(self):
while True:
try:
self.driver.find_element_by_class_name("tiles-content").click()
break
except:
time.sleep(TIMEOUT)
customPrint("Opened Channel", "INFO")
return True
def openLearningModule1(self):
while True:
try:
self.driver.find_element_by_xpath(
"//a[@class='tiles-title']").click()
"""listoanchors = self.driver.find_elements_by_xpath("//a[@class='tiles-title']")
a = None
for anchor in listoanchors:
anchor."""
break
except:
time.sleep(TIMEOUT)
customPrint("Opened Module", "INFO")
return True
def openLearningModule2(self):
while True:
try:
self.driver.find_elements_by_xpath(
"//a[@class='tiles-title']")[1].click()
"""listoanchors = self.driver.find_elements_by_xpath("//a[@class='tiles-title']")
a = None
for anchor in listoanchors:
anchor."""
break
except:
time.sleep(TIMEOUT)
customPrint("Opened Module", "INFO")
return True
def openLearningModule3(self):
while True:
try:
self.driver.find_elements_by_xpath(
"//a[@class='tiles-title']")[2].click()
"""listoanchors = self.driver.find_elements_by_xpath("//a[@class='tiles-title']")
a = None
for anchor in listoanchors:
anchor."""
break
except:
time.sleep(TIMEOUT)
customPrint("Opened Module", "INFO")
return True
def openLearningModuleN(self, n=0):
while True:
try:
self.driver.find_elements_by_css_selector(
'h4[class="title"]>a')[n].click()
"""listoanchors = self.driver.find_elements_by_xpath("//a[@class='tiles-title']")
a = None
for anchor in listoanchors:
anchor."""
break
except:
time.sleep(TIMEOUT)
customPrint("Opened Module", "INFO")
return True
def getFirstIncomplete(self):
while True:
try:
collapsibles = self.driver.find_elements_by_class_name(
"collapsible-content")
collapsibles.pop(0)
# collapsibles.pop(0)
customPrint("Got Collapsables", "INFO")
for collapsible in collapsibles:
items = None
try:
items = collapsible.find_elements_by_class_name(
"tiles-col-l")
except:
continue
for item in items:
iconOne = item.find_element_by_class_name(
"tiles-col-l-l")
textOne = item.find_element_by_class_name(
"tiles-col-l-r")
completedIndicatorIcon = iconOne.find_element_by_tag_name(
"span").find_element_by_tag_name("span")
completedIndicatorText = textOne.find_element_by_tag_name(
"span")
customPrint(completedIndicatorText.text)
if completedIndicatorIcon.get_attribute("data-title") == "Completed" or completedIndicatorText.text.lower().find("quiz") > -1 or completedIndicatorText.text.lower().find("exam") > -1:
customPrint("Already completed or quiz", "INFO")
continue
else:
customPrint("Found Incomplete", "INFO")
return item
return None
except Exception as err:
print(err)
time.sleep(TIMEOUT)
def completeOne(self, item):
customPrint("Completing One", "INFO")
while True:
try:
item.find_element_by_tag_name("a").click()
break
except:
time.sleep(TIMEOUT)
return True
def closeAllOtherHandles(self):
handles = self.driver.window_handles
size = len(handles)
for x in range(size):
if handles[x] != self.parent_handle:
self.driver.switch_to_window(handles[x])
print(self.driver.title)
self.driver.close()
self.driver.switch_to_window(self.parent_handle)
customPrint("Closed All Other Handles", "INFO")
def play(self):
while True:
try:
parent_window = self.driver.current_window_handle
p = self.driver.find_element_by_tag_name("p")
a = p.find_element_by_tag_name("a")
a.click()
time.sleep(READ_TIME)
self.closeAllOtherHandles()
break
except:
time.sleep(TIMEOUT)
customPrint("Completed a module", "SUCCESS")
return True
def goBackToLearningPath(self):
customPrint("Going back to learning path", "INFO")
self.driver.back()
self.driver.refresh()
time.sleep(5)
return True
while True:
try:
course = self.driver.find_element_by_id("userCourseLPSContent")
item = course.find_element_by_class_name(
"tiles-layout.table-tiles.three-col-tiles.clearboth")
item.click()
break
except:
time.sleep(TIMEOUT)
def close(self):
customPrint("Closed Bot", "INFO")
self.driver.close()