55 seleniumbase install {chromedriver|geckodriver|edgedriver|
66 iedriver|operadriver} [OPTIONS]
77Options:
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
1112Example:
1213 seleniumbase install chromedriver
14+ seleniumbase install geckodriver
1315 seleniumbase install chromedriver 76.0.3809.126
1416 seleniumbase install chromedriver latest
15- seleniumbase install geckodriver
17+ seleniumbase install chromedriver -p
18+ seleniumbase install chromedriver latest -p
1619Output:
17- Installs the specified webdriver.
20+ Installs the chosen webdriver to seleniumbase/drivers/
1821 (chromedriver is required for Chrome automation)
1922 (geckodriver is required for Firefox automation)
2023 (edgedriver is required for MS Edge automation)
3336from seleniumbase import drivers # webdriver storage folder for SeleniumBase
3437urllib3 .disable_warnings ()
3538DRIVER_DIR = os .path .dirname (os .path .realpath (drivers .__file__ ))
39+ LOCAL_PATH = "/usr/local/bin/" # On Mac and Linux systems
3640DEFAULT_CHROMEDRIVER_VERSION = "2.44"
3741DEFAULT_GECKODRIVER_VERSION = "v0.25.0"
3842DEFAULT_EDGEDRIVER_VERSION = "77.0.235.20"
39- DEFAULT_OPERADRIVER_VERSION = "v.2.40 "
43+ DEFAULT_OPERADRIVER_VERSION = "v.75.0.3770.100 "
4044
4145
4246def invalid_run_command ():
@@ -46,16 +50,19 @@ def invalid_run_command():
4650 exp += " (Drivers: chromedriver, geckodriver, edgedriver,\n "
4751 exp += " iedriver, operadriver)\n "
4852 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 "
5257 exp += " Example:\n "
5358 exp += " seleniumbase install chromedriver\n "
59+ exp += " seleniumbase install geckodriver\n "
5460 exp += " seleniumbase install chromedriver 76.0.3809.126\n "
5561 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 "
5764 exp += " Output:\n "
58- exp += " Installs the specified webdriver. \n "
65+ exp += " Installs the chosen webdriver to seleniumbase/drivers/ \n "
5966 exp += " (chromedriver is required for Chrome automation)\n "
6067 exp += " (geckodriver is required for Firefox automation)\n "
6168 exp += " (edgedriver is required for Microsoft Edge automation)\n "
@@ -76,7 +83,7 @@ def main():
7683 num_args = len (sys .argv )
7784 if sys .argv [0 ].split ('/' )[- 1 ].lower () == "seleniumbase" or (
7885 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 :
8087 invalid_run_command ()
8188 else :
8289 invalid_run_command ()
@@ -89,17 +96,26 @@ def main():
8996 expected_contents = None
9097 platform_code = None
9198 inner_folder = None
99+ copy_to_path = False
92100 use_version = ""
93101 new_file = ""
94102 f_name = ""
95103
96104 if name == "chromedriver" :
97105 use_version = DEFAULT_CHROMEDRIVER_VERSION
98106 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 ()
103119 if "darwin" in sys_plat :
104120 file_name = "chromedriver_mac64.zip"
105121 elif "linux" in sys_plat :
@@ -128,17 +144,25 @@ def main():
128144 elif name == "geckodriver" or name == "firefoxdriver" :
129145 use_version = DEFAULT_GECKODRIVER_VERSION
130146 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 ()
142166 if "darwin" in sys_plat :
143167 file_name = "geckodriver-%s-macos.tar.gz" % use_version
144168 elif "linux" in sys_plat :
@@ -166,10 +190,18 @@ def main():
166190 elif name == "edgedriver" or name == "msedgedriver" :
167191 name = "edgedriver"
168192 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 ()
173205 if "win64" in sys_plat or "x64" in sys_plat :
174206 file_name = "edgedriver_win64.zip"
175207 elif "win32" in sys_plat or "x86" in sys_plat :
@@ -197,6 +229,19 @@ def main():
197229 elif name == "operadriver" or name == "operachromiumdriver" :
198230 name = "operadriver"
199231 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 ()
200245 if "darwin" in sys_plat :
201246 file_name = "operadriver_mac64.zip"
202247 platform_code = "mac64"
@@ -278,6 +323,10 @@ def main():
278323 'systems.)\n ' % name )
279324 print ("Location of [%s %s]:\n %s" % (
280325 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 )
281330 print ("" )
282331 elif name == "edgedriver" or name == "msedgedriver" :
283332 if "darwin" in sys_plat or "linux" in sys_plat :
@@ -359,6 +408,10 @@ def main():
359408 print ("[%s] is now ready for use!\n " % driver_file )
360409 print ("Location of [%s %s]:\n %s" % (
361410 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 )
362415 # Clean up extra files
363416 if os .path .exists (inner_driver ):
364417 os .remove (inner_driver )
@@ -400,6 +453,10 @@ def main():
400453 'systems.)\n ' % name )
401454 print ("Location of [%s %s]:\n %s" % (
402455 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 )
403460 print ("" )
404461 elif len (contents ) == 0 :
405462 raise Exception ("Tar file %s is empty!" % tar_file_path )
0 commit comments