8
8
(chromedriver is required for Chrome automation)
9
9
(geckodriver is required for Firefox automation)
10
10
(edgedriver is required for MS Edge automation)
11
+ (iedriver is required for Internet Explorer automation)
12
+ (operadriver is required for Opera Browser automation)
11
13
"""
12
14
13
15
import os
14
16
import platform
15
17
import requests
18
+ import shutil
16
19
import sys
17
20
import tarfile
18
21
import zipfile
@@ -28,14 +31,17 @@ def invalid_run_command():
28
31
exp = (" ** install **\n \n " )
29
32
exp += " Usage:\n "
30
33
exp += " seleniumbase install [DRIVER_NAME]\n "
31
- exp += " (Drivers: chromedriver, geckodriver, edgedriver)\n "
34
+ exp += " (Drivers: chromedriver, geckodriver, edgedriver,\n "
35
+ exp += " iedriver, operadriver)\n "
32
36
exp += " Example:\n "
33
37
exp += " seleniumbase install chromedriver\n "
34
38
exp += " Output:\n "
35
39
exp += " Installs the specified webdriver.\n "
36
40
exp += " (chromedriver is required for Chrome automation)\n "
37
41
exp += " (geckodriver is required for Firefox automation)\n "
38
- exp += " (edgedriver is required for MS Edge automation)\n "
42
+ exp += " (edgedriver is required for Microsoft Edge automation)\n "
43
+ exp += " (iedriver is required for InternetExplorer automation)\n "
44
+ exp += " (operadriver is required for Opera Browser automation)\n "
39
45
print ("" )
40
46
raise Exception ('INVALID RUN COMMAND!\n \n %s' % exp )
41
47
@@ -60,16 +66,20 @@ def main():
60
66
file_name = None
61
67
download_url = None
62
68
downloads_folder = DRIVER_DIR
69
+ sys_plat = sys .platform
70
+ expected_contents = None
71
+ platform_code = None
72
+ inner_folder = None
63
73
64
74
if name == "chromedriver" :
65
- if "darwin" in sys . platform :
75
+ if "darwin" in sys_plat :
66
76
file_name = "chromedriver_mac64.zip"
67
- elif "linux" in sys . platform :
77
+ elif "linux" in sys_plat :
68
78
file_name = "chromedriver_linux64.zip"
69
- elif "win32" in sys . platform or "win64" in sys . platform :
70
- file_name = "chromedriver_win32.zip" # Works for win32 and win64
79
+ elif "win32" in sys_plat or "win64" in sys_plat or "x64" in sys_plat :
80
+ file_name = "chromedriver_win32.zip" # Works for win32 / win_x64
71
81
else :
72
- raise Exception ("Cannon determine which version of Chromedriver "
82
+ raise Exception ("Cannot determine which version of Chromedriver "
73
83
"to download!" )
74
84
75
85
latest_version = requests .get (
@@ -85,34 +95,85 @@ def main():
85
95
print ("Found %s" % download_url )
86
96
elif name == "geckodriver" or name == "firefoxdriver" :
87
97
latest_version = "v0.21.0"
88
- if "darwin" in sys . platform :
98
+ if "darwin" in sys_plat :
89
99
file_name = "geckodriver-%s-macos.tar.gz" % latest_version
90
- elif "linux" in sys . platform :
100
+ elif "linux" in sys_plat :
91
101
arch = platform .architecture ()[0 ]
92
102
if "64" in arch :
93
103
file_name = "geckodriver-%s-linux64.tar.gz" % latest_version
94
104
else :
95
105
file_name = "geckodriver-%s-linux32.tar.gz" % latest_version
96
- elif "win32" in sys . platform :
106
+ elif "win32" in sys_plat :
97
107
file_name = "geckodriver-%s-win32.zip" % latest_version
98
- elif "win64" in sys . platform :
108
+ elif "win64" in sys_plat or "x64" in sys_plat :
99
109
file_name = "geckodriver-%s-win64.zip" % latest_version
100
110
else :
101
- raise Exception ("Cannon determine which version of Geckodriver "
111
+ raise Exception ("Cannot determine which version of Geckodriver "
102
112
"(Firefox Driver) to download!" )
103
113
104
- download_url = ("http ://github.com/mozilla/geckodriver/"
114
+ download_url = ("https ://github.com/mozilla/geckodriver/"
105
115
"releases/download/"
106
116
"%s/%s" % (latest_version , file_name ))
107
117
elif name == "edgedriver" or name == "microsoftwebdriver" :
108
- if "win32" in sys .platform or "win64" in sys .platform :
109
- version_code = "F/8/A/F8AF50AB-3C3A-4BC4-8773-DC27B32988DD"
118
+ name = "edgedriver"
119
+ version_code = "F/8/A/F8AF50AB-3C3A-4BC4-8773-DC27B32988DD"
120
+ if "win32" in sys_plat or "win64" in sys_plat or "x64" in sys_plat :
110
121
file_name = "MicrosoftWebDriver.exe"
111
- download_url = ("https://download.microsoft.com/download/"
112
- "%s/%s" % (version_code , file_name ))
113
122
else :
114
123
raise Exception ("Sorry! Microsoft WebDriver / EdgeDriver is "
115
124
"only for Windows-based operating systems!" )
125
+ download_url = ("https://download.microsoft.com/download/"
126
+ "%s/%s" % (version_code , file_name ))
127
+ elif name == "iedriver" :
128
+ major_version = "3.11"
129
+ full_version = "3.11.1"
130
+ if "win32" in sys_plat :
131
+ file_name = "IEDriverServer_Win32_%s.zip" % full_version
132
+ elif "win64" in sys_plat or "x64" in sys_plat :
133
+ file_name = "IEDriverServer_x64_%s.zip" % full_version
134
+ else :
135
+ raise Exception ("Sorry! IEDriver is only for "
136
+ "Windows-based operating systems!" )
137
+ download_url = ("http://selenium-release.storage.googleapis.com/"
138
+ "%s/%s" % (major_version , file_name ))
139
+ elif name == "operadriver" or name == "operachromiumdriver" :
140
+ name = "operadriver"
141
+ latest_version = "v.2.37"
142
+ if "darwin" in sys_plat :
143
+ file_name = "operadriver_mac64.zip"
144
+ platform_code = "mac64"
145
+ inner_folder = "operadriver_%s/" % platform_code
146
+ expected_contents = (['operadriver_mac64/' ,
147
+ 'operadriver_mac64/operadriver' ,
148
+ 'operadriver_mac64/sha512_sum' ])
149
+ elif "linux" in sys_plat :
150
+ file_name = "operadriver_linux64.zip"
151
+ platform_code = "linux64"
152
+ inner_folder = "operadriver_%s/" % platform_code
153
+ expected_contents = (['operadriver_linux64/' ,
154
+ 'operadriver_linux64/operadriver' ,
155
+ 'operadriver_linux64/sha512_sum' ])
156
+ elif "win32" in sys_plat :
157
+ file_name = "operadriver_win32.zip"
158
+ platform_code = "win32"
159
+ inner_folder = "operadriver_%s/" % platform_code
160
+ expected_contents = (['operadriver_win32/' ,
161
+ 'operadriver_win32/operadriver.exe' ,
162
+ 'operadriver_win32/sha512_sum' ])
163
+ elif "win64" in sys_plat or "x64" in sys_plat :
164
+ file_name = "operadriver_win64.zip"
165
+ platform_code = "win64"
166
+ inner_folder = "operadriver_%s/" % platform_code
167
+ expected_contents = (['operadriver_win64/' ,
168
+ 'operadriver_win64/operadriver.exe' ,
169
+ 'operadriver_win64/sha512_sum' ])
170
+ else :
171
+ raise Exception ("Cannot determine which version of Operadriver "
172
+ "to download!" )
173
+
174
+ download_url = ("https://github.com/operasoftware/operachromiumdriver/"
175
+ "releases/download/"
176
+ "%s/%s" % (latest_version , file_name ))
116
177
else :
117
178
invalid_run_command ()
118
179
@@ -135,6 +196,8 @@ def main():
135
196
zip_ref = zipfile .ZipFile (zip_file_path , 'r' )
136
197
contents = zip_ref .namelist ()
137
198
if len (contents ) == 1 :
199
+ if name == "operadriver" :
200
+ raise Exception ("Zip file for OperaDriver is missing content!" )
138
201
for f_name in contents :
139
202
# remove existing version if exists
140
203
new_file = downloads_folder + '/' + str (f_name )
@@ -153,6 +216,46 @@ def main():
153
216
make_executable (new_file )
154
217
print ("%s is now ready for use!" % new_file )
155
218
print ("" )
219
+ elif name == "operadriver" :
220
+ if len (contents ) != 3 :
221
+ raise Exception ("Unexpected content in OperaDriver Zip file!" )
222
+ elif sorted (contents ) != sorted (expected_contents ):
223
+ raise Exception ("Unexpected content in OperaDriver Zip file!" )
224
+ # Zip file is valid. Proceed.
225
+ driver_path = None
226
+ driver_file = None
227
+ for f_name in contents :
228
+ # remove existing version if exists
229
+ str_name = str (f_name ).split (inner_folder )[1 ]
230
+ new_file = downloads_folder + '/' + str_name
231
+ if str_name == "operadriver" or str_name == "operadriver.exe" :
232
+ driver_file = str_name
233
+ driver_path = new_file
234
+ if os .path .exists (new_file ):
235
+ os .remove (new_file )
236
+ if not driver_file or not driver_path :
237
+ raise Exception ("Operadriver missing from Zip file!" )
238
+ print ('Extracting %s from %s ...' % (contents , file_name ))
239
+ zip_ref .extractall (downloads_folder )
240
+ zip_ref .close ()
241
+ os .remove (zip_file_path )
242
+ print ('Unzip Complete!\n ' )
243
+ inner_driver = downloads_folder + '/' + inner_folder + driver_file
244
+ inner_sha = downloads_folder + '/' + inner_folder + "sha512_sum"
245
+ shutil .copyfile (inner_driver , driver_path )
246
+ print ("%s saved!\n " % driver_path )
247
+ print ("Making %s executable ..." % driver_path )
248
+ make_executable (driver_path )
249
+ print ("%s is now ready for use!" % driver_path )
250
+ # clean up extra files
251
+ if os .path .exists (inner_driver ):
252
+ os .remove (inner_driver )
253
+ if os .path .exists (inner_sha ):
254
+ os .remove (inner_sha )
255
+ if os .path .exists (downloads_folder + '/' + inner_folder ):
256
+ # only works if the directory is empty
257
+ os .rmdir (downloads_folder + '/' + inner_folder )
258
+ print ("" )
156
259
elif len (contents ) == 0 :
157
260
raise Exception ("Zip file %s is empty!" % zip_file_path )
158
261
else :
@@ -172,7 +275,7 @@ def main():
172
275
tar .extractall (downloads_folder )
173
276
tar .close ()
174
277
os .remove (tar_file_path )
175
- print ('Untar Complete!\n ' )
278
+ print ('Unzip Complete!\n ' )
176
279
for f_name in contents :
177
280
new_file = downloads_folder + '/' + str (f_name )
178
281
print ("%s saved!\n " % new_file )
0 commit comments