-
Notifications
You must be signed in to change notification settings - Fork 0
/
association.py
253 lines (232 loc) · 10.4 KB
/
association.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import elem as elem
import selenium
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions
driver = webdriver.Chrome("C:\chromedriver.exe")
driver.maximize_window()
http1 = "www.abc.com"
http2 = "www.def.com"
username = "artur"
password = "qwerty123"
def log_in():
try:
driver.get(http1)
time.sleep(1)
click_xpath_element('//*[@id="loginMessageOkCancelButton"]')
elem = driver.find_element_by_id("j_username")
elem.clear()
elem.send_keys(username)
elem.send_keys(Keys.RETURN)
elem = driver.find_element_by_id("j_password")
elem.clear()
elem.send_keys(password)
elem.send_keys(Keys.RETURN)
time.sleep(1)
elem = driver.find_element_by_id('loginPanelSubmitButton')
elem.click()
except:
print "Login"
def click_xpath_element(xpath):
# And check what was found
try:
WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, xpath)))
elem = driver.find_element_by_xpath(xpath)
elem.click()
time.sleep(1)
except TimeoutException:
pass
def main():
suffix = "_loc"
friendly_names1 = []
friendly_names2 = []
friendly_names3 = []
friendly_names4 = []
log_in()
j = 11295 # starting ID of devices to association
'''
###################################################################################################
# association devices to groups loc_1 - loc_9
###################################################################################################
for i in range(9, 10, 1):
friendly_name = str(0) + str(0) + str(0) + str(i) + suffix
friendly_names1.append(friendly_name)
# go to static groups, find proper group and edit it
for name in friendly_names1:
driver.get(http2)
elem = driver.find_element_by_xpath('//input[@placeholder="Search.."]')
elem.click()
elem.send_keys(name)
elem.send_keys(Keys.RETURN)
click_xpath_element('//*[@type="checkbox"]')
time.sleep(1)
click_xpath_element('//*[@id="gridComponent-grid-edit"]')
# associate devices with defined ID
for z in range(1, 6, 1):
click_xpath_element('//*[@id="userdevicereslist-grid-associate_devices_id"]')
time.sleep(1)
elem = driver.find_element_by_xpath('//a[@class="add-on btn dropdown-toggle"]')
elem.click()
click_xpath_element('//ul[@class="dropdown-menu pull-right"]')
click_xpath_element('//*[@id="id30b"]')
click_xpath_element('//option[@value="criteria.startsWith"]')
time.sleep(1)
elem = driver.find_element_by_xpath('//input[@type="text"]')
elem.click()
elem.send_keys(j)
j = j + 1
time.sleep(1)
elem.send_keys(Keys.PAGE_DOWN)
elem.send_keys(Keys.PAGE_DOWN)
time.sleep(1)
click_xpath_element('//*[@id="searchPanel-searchPanel-search"]')
time.sleep(2)
click_xpath_element('//input[@name="searchPanel:searchPanel-grid:grid:datatable:topToolbars:toolbars:1:headers:14:header:label:selected"]')
time.sleep(2)
click_xpath_element('//*[@id="searchPanel-grid-submit_id"]')
time.sleep(1)
# submit changes for a static group
elem = driver.find_element_by_xpath('//*[@id="editor-submit"]')
elem.click()
time.sleep(1)
###################################################################################################
# association devices to groups loc_10 - loc_99
###################################################################################################
for n in range(31, 100, 1):
friendly_name = str(0) + str(0) + str(n) + suffix
friendly_names2.append(friendly_name)
# go to static groups, find proper group and edit it
for name in friendly_names2:
driver.get(http2)
elem = driver.find_element_by_xpath('//input[@placeholder="Search.."]')
elem.click()
elem.send_keys(name)
elem.send_keys(Keys.RETURN)
click_xpath_element('//*[@type="checkbox"]')
click_xpath_element('//*[@id="gridComponent-grid-edit"]')
time.sleep(1)
# associate devices with defined ID
for z in range(1, 6, 1):
click_xpath_element('//*[@id="userdevicereslist-grid-associate_devices_id"]')
time.sleep(1)
elem = driver.find_element_by_xpath('//a[@class="add-on btn dropdown-toggle"]')
elem.click()
click_xpath_element('//ul[@class="dropdown-menu pull-right"]')
click_xpath_element('//*[@id="id30b"]')
click_xpath_element('//option[@value="criteria.startsWith"]')
time.sleep(1)
elem = driver.find_element_by_xpath('//input[@type="text"]')
elem.click()
elem.send_keys(j)
j = j + 1
time.sleep(1)
elem.send_keys(Keys.PAGE_DOWN)
elem.send_keys(Keys.PAGE_DOWN)
time.sleep(1)
click_xpath_element('//*[@id="searchPanel-searchPanel-search"]')
time.sleep(2)
click_xpath_element('//input[@name="searchPanel:searchPanel-grid:grid:datatable:topToolbars:toolbars:1:headers:14:header:label:selected"]')
time.sleep(2)
click_xpath_element('//*[@id="searchPanel-grid-submit_id"]')
time.sleep(1)
# submit changes for a static group
elem = driver.find_element_by_xpath('//*[@id="editor-submit"]')
elem.click()
time.sleep(1)
###################################################################################################
# association devices to groups loc_100 - loc_999
###################################################################################################
for m in range(881, 1000, 1):
friendly_name = str(0) + str(m) + suffix
friendly_names3.append(friendly_name)
# go to static groups, find proper group and edit it
for name in friendly_names3:
driver.get(http2)
elem = driver.find_element_by_xpath('//input[@placeholder="Search.."]')
elem.click()
elem.send_keys(name)
elem.send_keys(Keys.RETURN)
time.sleep(1)
click_xpath_element('//*[@type="checkbox"]')
click_xpath_element('//*[@id="gridComponent-grid-edit"]')
time.sleep(1)
# associate devices with defined ID
for z in range(1, 6, 1):
click_xpath_element('//*[@id="userdevicereslist-grid-associate_devices_id"]')
time.sleep(1)
elem = driver.find_element_by_xpath('//a[@class="add-on btn dropdown-toggle"]')
elem.click()
click_xpath_element('//ul[@class="dropdown-menu pull-right"]')
click_xpath_element('//*[@id="id30b"]')
click_xpath_element('//option[@value="criteria.startsWith"]')
time.sleep(1)
elem = driver.find_element_by_xpath('//input[@type="text"]')
time.sleep(1)
elem.click()
elem.send_keys(j)
j = j + 1
time.sleep(1)
elem.send_keys(Keys.PAGE_DOWN)
elem.send_keys(Keys.PAGE_DOWN)
time.sleep(1)
click_xpath_element('//*[@id="searchPanel-searchPanel-search"]')
time.sleep(2)
click_xpath_element('//input[@name="searchPanel:searchPanel-grid:grid:datatable:topToolbars:toolbars:1:headers:14:header:label:selected"]')
time.sleep(2)
click_xpath_element('//*[@id="searchPanel-grid-submit_id"]')
time.sleep(1)
# submit changes for a static group
elem = driver.find_element_by_xpath('//*[@id="editor-submit"]')
elem.click()
time.sleep(1)
'''
###################################################################################################
# association devices to groups loc_1000 - loc_1260
###################################################################################################
for p in range(1240, 1261, 1):
friendly_name = str(p) + suffix
friendly_names4.append(friendly_name)
# go to static groups, find proper group and edit it
for name in friendly_names4:
driver.get(http2)
elem = driver.find_element_by_xpath('//input[@placeholder="Search.."]')
elem.click()
elem.send_keys(name)
elem.send_keys(Keys.RETURN)
click_xpath_element('//*[@type="checkbox"]')
click_xpath_element('//*[@id="gridComponent-grid-edit"]')
time.sleep(1)
# associate devices with defined ID
for z in range(1, 6, 1):
click_xpath_element('//*[@id="userdevicereslist-grid-associate_devices_id"]')
time.sleep(1)
elem = driver.find_element_by_xpath('//a[@class="add-on btn dropdown-toggle"]')
elem.click()
click_xpath_element('//ul[@class="dropdown-menu pull-right"]')
click_xpath_element('//*[@id="id30b"]')
click_xpath_element('//option[@value="criteria.startsWith"]')
time.sleep(1)
elem = driver.find_element_by_xpath('//input[@type="text"]')
elem.click()
elem.send_keys(j)
j = j + 1
time.sleep(1)
elem.send_keys(Keys.PAGE_DOWN)
elem.send_keys(Keys.PAGE_DOWN)
time.sleep(1)
click_xpath_element('//*[@id="searchPanel-searchPanel-search"]')
time.sleep(2)
click_xpath_element('//input[@name="searchPanel:searchPanel-grid:grid:datatable:topToolbars:toolbars:1:headers:14:header:label:selected"]')
time.sleep(2)
click_xpath_element('//*[@id="searchPanel-grid-submit_id"]')
time.sleep(1)
# submit changes for a static group
elem = driver.find_element_by_xpath('//*[@id="editor-submit"]')
elem.click()
time.sleep(1)
if __name__ == '__main__':
main()