1
1
from selenium import webdriver
2
2
from selenium .common import exceptions
3
3
from selenium .webdriver .chrome import options
4
+ from selenium .webdriver .common .by import By
5
+ from selenium .webdriver .chrome .service import Service
4
6
from random import randint
5
7
from random import normalvariate
6
8
import requests
@@ -33,8 +35,9 @@ def report(user_index, try_times):
33
35
34
36
print ('[Info] Launching Browser' )
35
37
if (config .driver_path != 'auto' ):
38
+ service = Service (config .driver_path )
36
39
browser = webdriver .Chrome (
37
- config . driver_path , options = chrome_options )
40
+ service = service , options = chrome_options )
38
41
else :
39
42
browser = webdriver .Chrome (options = chrome_options )
40
43
@@ -45,19 +48,19 @@ def report(user_index, try_times):
45
48
browser .get ('https://id.sspu.edu.cn/cas/login' )
46
49
time .sleep (1 )
47
50
48
- username_box = browser .find_element_by_id ( 'username' )
51
+ username_box = browser .find_element ( By . ID , 'username' )
49
52
username_box .send_keys (config .users [user_index ]['username' ])
50
- password_box = browser .find_element_by_id ( 'password' )
53
+ password_box = browser .find_element ( By . ID , 'password' )
51
54
password_box .send_keys (config .users [user_index ]['password' ])
52
55
time .sleep (0.5 )
53
56
54
- login_button = browser .find_element_by_class_name ( 'submit_button' )
57
+ login_button = browser .find_element ( By . CLASS_NAME , 'submit_button' )
55
58
login_button .click ()
56
59
time .sleep (1 )
57
60
58
61
# Detect login status
59
62
try :
60
- browser .find_element_by_class_name ( 'success' )
63
+ browser .find_element ( By . CLASS_NAME , 'success' )
61
64
except exceptions .NoSuchElementException :
62
65
print ('[Error] Login failed' )
63
66
if config .users [user_index ]['use_wechat' ]:
@@ -96,36 +99,36 @@ def report(user_index, try_times):
96
99
print ('[Info] Auto generated temperature:' , temperature )
97
100
98
101
# Fill temperature
99
- temperature_box = browser .find_element_by_id ( 'p1_TiWen-inputEl' )
102
+ temperature_box = browser .find_element ( By . ID , 'p1_TiWen-inputEl' )
100
103
temperature_box .clear ()
101
104
temperature_box .send_keys (str (temperature ))
102
105
time .sleep (0.5 )
103
106
104
107
# Health Condition
105
- condition_good = browser .find_element_by_id ( 'p1_DangQSTZK' ) \
106
- .find_element_by_xpath ( "//*[contains(text(), 'Good')]" )
108
+ condition_good = browser .find_element ( By . ID , 'p1_DangQSTZK' ) \
109
+ .find_element ( By . XPATH , "//*[contains(text(), 'Good')]" )
107
110
condition_good .click ()
108
111
time .sleep (0.5 )
109
112
110
113
# In Shanghai
111
114
if config .users [user_index ]['in_shanghai' ]:
112
- in_shanghai = browser .find_element_by_id ( 'p1_Shanghai' ) \
113
- .find_element_by_class_name ( 'f-field-body-cell' ) \
114
- .find_element_by_class_name ( 'f-field-checkbox-switch' )
115
+ in_shanghai = browser .find_element ( By . ID , 'p1_Shanghai' ) \
116
+ .find_element ( By . CLASS_NAME , 'f-field-body-cell' ) \
117
+ .find_element ( By . CLASS_NAME , 'f-field-checkbox-switch' )
115
118
in_shanghai .click ()
116
119
time .sleep (0.5 )
117
120
118
121
# Submit
119
- submit_button = browser .find_element_by_id ( 'p1_ctl00' ) \
120
- .find_element_by_id ( 'p1_ctl00_btnSubmit' )
122
+ submit_button = browser .find_element ( By . ID , 'p1_ctl00' ) \
123
+ .find_element ( By . ID , 'p1_ctl00_btnSubmit' )
121
124
submit_button .click ()
122
125
time .sleep (1 )
123
126
124
127
# Waiting for submit result
125
128
for i in range (int (config .timeout / 3 )):
126
129
try :
127
- browser .find_element_by_class_name ( 'f-window' ) \
128
- .find_elements_by_xpath (
130
+ browser .find_element ( By . CLASS_NAME , 'f-window' ) \
131
+ .find_elements ( By . XPATH ,
129
132
"//*[contains(text(), 'Submit successfully')]" )
130
133
except exceptions .NoSuchElementException :
131
134
time .sleep (3 )
@@ -135,8 +138,8 @@ def report(user_index, try_times):
135
138
break
136
139
137
140
try :
138
- browser .find_element_by_class_name ( 'f-window' ) \
139
- .find_elements_by_xpath (
141
+ browser .find_element ( By . CLASS_NAME , 'f-window' ) \
142
+ .find_elements ( By . XPATH ,
140
143
"//*[contains(text(), 'Submit successfully')]" )
141
144
except exceptions .NoSuchElementException :
142
145
print ('[Error] Submit timeout' )
@@ -150,8 +153,8 @@ def report(user_index, try_times):
150
153
print ('[Info] Reported successfully' )
151
154
152
155
# Click done
153
- done_button = browser .find_element_by_class_name ( 'f-window' ) \
154
- .find_element_by_class_name ( 'f-btn' )
156
+ done_button = browser .find_element ( By . CLASS_NAME , 'f-window' ) \
157
+ .find_element ( By . CLASS_NAME , 'f-btn' )
155
158
done_button .click ()
156
159
time .sleep (1 )
157
160
@@ -160,9 +163,9 @@ def report(user_index, try_times):
160
163
time .sleep (1 )
161
164
162
165
# Get rank data text
163
- txt = browser .find_element_by_id ( 'Panel1_DataList1' ) \
164
- .find_element_by_class_name ( 'f-datalist-list' ) \
165
- .find_elements_by_class_name ( 'f-datalist-item-inner' )[0 ].text
166
+ txt = browser .find_element ( By . ID , 'Panel1_DataList1' ) \
167
+ .find_element ( By . CLASS_NAME , 'f-datalist-list' ) \
168
+ .find_elements ( By . CLASS_NAME , 'f-datalist-item-inner' )[0 ].text
166
169
167
170
# Check whether report is successful
168
171
if txt .find (strings .msg ['success_msg' ]) == - 1 :
0 commit comments