5
5
seleniumbase install {chromedriver|geckodriver|edgedriver|
6
6
iedriver|operadriver} [OPTIONS]
7
7
Options:
8
- VERSION - Specify version
9
- (Default Chromedriver version = 2.44)
10
- Use "latest" for the latest version.
8
+ VERSION Specify the version.
9
+ (Default Chromedriver version = 2.44)
10
+ Use "latest" for the latest version.
11
+ -p OR --path Also copy the driver to /usr/local/bin
11
12
Example:
12
13
seleniumbase install chromedriver
14
+ seleniumbase install geckodriver
13
15
seleniumbase install chromedriver 76.0.3809.126
14
16
seleniumbase install chromedriver latest
15
- seleniumbase install geckodriver
17
+ seleniumbase install chromedriver -p
18
+ seleniumbase install chromedriver latest -p
16
19
Output:
17
- Installs the specified webdriver.
20
+ Installs the chosen webdriver to seleniumbase/drivers/
18
21
(chromedriver is required for Chrome automation)
19
22
(geckodriver is required for Firefox automation)
20
23
(edgedriver is required for MS Edge automation)
33
36
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
34
37
urllib3 .disable_warnings ()
35
38
DRIVER_DIR = os .path .dirname (os .path .realpath (drivers .__file__ ))
39
+ LOCAL_PATH = "/usr/local/bin/" # On Mac and Linux systems
36
40
DEFAULT_CHROMEDRIVER_VERSION = "2.44"
37
41
DEFAULT_GECKODRIVER_VERSION = "v0.25.0"
38
42
DEFAULT_EDGEDRIVER_VERSION = "77.0.235.20"
39
- DEFAULT_OPERADRIVER_VERSION = "v.2.40 "
43
+ DEFAULT_OPERADRIVER_VERSION = "v.75.0.3770.100 "
40
44
41
45
42
46
def invalid_run_command ():
@@ -46,16 +50,19 @@ def invalid_run_command():
46
50
exp += " (Drivers: chromedriver, geckodriver, edgedriver,\n "
47
51
exp += " iedriver, operadriver)\n "
48
52
exp += " Options:\n "
49
- exp += " VERSION - Specify version (Chromedriver / EdgeDr ONLY)."
50
- exp += " (Default Chromedriver version = 2.44)"
51
- exp += ' Use "latest" to get the latest Chromedriver.'
53
+ exp += " VERSION Specify the version.\n "
54
+ exp += " (Default Chromedriver version = 2.44)\n "
55
+ exp += ' Use "latest" for the latest version.\n '
56
+ exp += " -p OR --path Also copy the driver to /usr/local/bin\n "
52
57
exp += " Example:\n "
53
58
exp += " seleniumbase install chromedriver\n "
59
+ exp += " seleniumbase install geckodriver\n "
54
60
exp += " seleniumbase install chromedriver 76.0.3809.126\n "
55
61
exp += " seleniumbase install chromedriver latest\n "
56
- exp += " seleniumbase install geckodriver\n "
62
+ exp += " seleniumbase install chromedriver -p\n "
63
+ exp += " seleniumbase install chromedriver latest -p\n "
57
64
exp += " Output:\n "
58
- exp += " Installs the specified webdriver. \n "
65
+ exp += " Installs the chosen webdriver to seleniumbase/drivers/ \n "
59
66
exp += " (chromedriver is required for Chrome automation)\n "
60
67
exp += " (geckodriver is required for Firefox automation)\n "
61
68
exp += " (edgedriver is required for Microsoft Edge automation)\n "
@@ -76,7 +83,7 @@ def main():
76
83
num_args = len (sys .argv )
77
84
if sys .argv [0 ].split ('/' )[- 1 ].lower () == "seleniumbase" or (
78
85
sys .argv [0 ].split ('\\ ' )[- 1 ].lower () == "seleniumbase" ):
79
- if num_args < 3 or num_args > 4 :
86
+ if num_args < 3 or num_args > 5 :
80
87
invalid_run_command ()
81
88
else :
82
89
invalid_run_command ()
@@ -89,17 +96,26 @@ def main():
89
96
expected_contents = None
90
97
platform_code = None
91
98
inner_folder = None
99
+ copy_to_path = False
92
100
use_version = ""
93
101
new_file = ""
94
102
f_name = ""
95
103
96
104
if name == "chromedriver" :
97
105
use_version = DEFAULT_CHROMEDRIVER_VERSION
98
106
get_latest = False
99
- if num_args == 4 :
100
- use_version = sys .argv [3 ]
101
- if use_version .lower () == "latest" :
102
- get_latest = True
107
+ if num_args == 4 or num_args == 5 :
108
+ if "-p" not in sys .argv [3 ].lower ():
109
+ use_version = sys .argv [3 ]
110
+ if use_version .lower () == "latest" :
111
+ get_latest = True
112
+ else :
113
+ copy_to_path = True
114
+ if num_args == 5 :
115
+ if "-p" in sys .argv [4 ].lower ():
116
+ copy_to_path = True
117
+ else :
118
+ invalid_run_command ()
103
119
if "darwin" in sys_plat :
104
120
file_name = "chromedriver_mac64.zip"
105
121
elif "linux" in sys_plat :
@@ -128,17 +144,25 @@ def main():
128
144
elif name == "geckodriver" or name == "firefoxdriver" :
129
145
use_version = DEFAULT_GECKODRIVER_VERSION
130
146
found_geckodriver = False
131
- if num_args == 4 :
132
- use_version = sys .argv [3 ]
133
- if use_version .lower () == "latest" :
134
- last = ("https://api.github.com/repos/"
135
- "mozilla/geckodriver/releases/latest" )
136
- url_request = requests .get (last )
137
- if url_request .ok :
138
- found_geckodriver = True
139
- use_version = url_request .json ()["tag_name" ]
140
- else :
141
- use_version = DEFAULT_GECKODRIVER_VERSION
147
+ if num_args == 4 or num_args == 5 :
148
+ if "-p" not in sys .argv [3 ].lower ():
149
+ use_version = sys .argv [3 ]
150
+ if use_version .lower () == "latest" :
151
+ last = ("https://api.github.com/repos/"
152
+ "mozilla/geckodriver/releases/latest" )
153
+ url_request = requests .get (last )
154
+ if url_request .ok :
155
+ found_geckodriver = True
156
+ use_version = url_request .json ()["tag_name" ]
157
+ else :
158
+ use_version = DEFAULT_GECKODRIVER_VERSION
159
+ else :
160
+ copy_to_path = True
161
+ if num_args == 5 :
162
+ if "-p" in sys .argv [4 ].lower ():
163
+ copy_to_path = True
164
+ else :
165
+ invalid_run_command ()
142
166
if "darwin" in sys_plat :
143
167
file_name = "geckodriver-%s-macos.tar.gz" % use_version
144
168
elif "linux" in sys_plat :
@@ -166,10 +190,18 @@ def main():
166
190
elif name == "edgedriver" or name == "msedgedriver" :
167
191
name = "edgedriver"
168
192
use_version = DEFAULT_EDGEDRIVER_VERSION
169
- if num_args == 4 :
170
- use_version = sys .argv [3 ]
171
- if use_version .lower () == "latest" :
172
- use_version = DEFAULT_EDGEDRIVER_VERSION
193
+ if num_args == 4 or num_args == 5 :
194
+ if "-p" not in sys .argv [3 ].lower ():
195
+ use_version = sys .argv [3 ]
196
+ if use_version .lower () == "latest" :
197
+ use_version = DEFAULT_EDGEDRIVER_VERSION
198
+ else :
199
+ copy_to_path = True
200
+ if num_args == 5 :
201
+ if "-p" in sys .argv [4 ].lower ():
202
+ copy_to_path = True
203
+ else :
204
+ invalid_run_command ()
173
205
if "win64" in sys_plat or "x64" in sys_plat :
174
206
file_name = "edgedriver_win64.zip"
175
207
elif "win32" in sys_plat or "x86" in sys_plat :
@@ -197,6 +229,19 @@ def main():
197
229
elif name == "operadriver" or name == "operachromiumdriver" :
198
230
name = "operadriver"
199
231
use_version = DEFAULT_OPERADRIVER_VERSION
232
+ get_latest = False
233
+ if num_args == 4 or num_args == 5 :
234
+ if "-p" not in sys .argv [3 ].lower ():
235
+ use_version = sys .argv [3 ]
236
+ if use_version .lower () == "latest" :
237
+ use_version = DEFAULT_OPERADRIVER_VERSION
238
+ else :
239
+ copy_to_path = True
240
+ if num_args == 5 :
241
+ if "-p" in sys .argv [4 ].lower ():
242
+ copy_to_path = True
243
+ else :
244
+ invalid_run_command ()
200
245
if "darwin" in sys_plat :
201
246
file_name = "operadriver_mac64.zip"
202
247
platform_code = "mac64"
@@ -278,6 +323,10 @@ def main():
278
323
'systems.)\n ' % name )
279
324
print ("Location of [%s %s]:\n %s" % (
280
325
f_name , use_version , new_file ))
326
+ if copy_to_path and os .path .exists (LOCAL_PATH ):
327
+ path_file = LOCAL_PATH + f_name
328
+ shutil .copyfile (new_file , path_file )
329
+ print ("Also copied to: %s" % path_file )
281
330
print ("" )
282
331
elif name == "edgedriver" or name == "msedgedriver" :
283
332
if "darwin" in sys_plat or "linux" in sys_plat :
@@ -359,6 +408,10 @@ def main():
359
408
print ("[%s] is now ready for use!\n " % driver_file )
360
409
print ("Location of [%s %s]:\n %s" % (
361
410
driver_file , use_version , driver_path ))
411
+ if copy_to_path and os .path .exists (LOCAL_PATH ):
412
+ path_file = LOCAL_PATH + driver_file
413
+ shutil .copyfile (driver_path , path_file )
414
+ print ("Also copied to: %s" % path_file )
362
415
# Clean up extra files
363
416
if os .path .exists (inner_driver ):
364
417
os .remove (inner_driver )
@@ -400,6 +453,10 @@ def main():
400
453
'systems.)\n ' % name )
401
454
print ("Location of [%s %s]:\n %s" % (
402
455
f_name , use_version , new_file ))
456
+ if copy_to_path and os .path .exists (LOCAL_PATH ):
457
+ path_file = LOCAL_PATH + f_name
458
+ shutil .copyfile (new_file , path_file )
459
+ print ("Also copied to: %s" % path_file )
403
460
print ("" )
404
461
elif len (contents ) == 0 :
405
462
raise Exception ("Tar file %s is empty!" % tar_file_path )
0 commit comments