Skip to content

Commit 30ed10b

Browse files
committed
If the expected webdriver isn't installed, install it automatically
1 parent f47185e commit 30ed10b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ def make_driver_executable_if_not(driver_path):
7373
make_executable(driver_path)
7474

7575

76+
def is_chromedriver_on_path():
77+
paths = os.environ["PATH"].split(os.pathsep)
78+
for path in paths:
79+
if os.path.exists(path + '/' + "chromedriver"):
80+
return True
81+
return False
82+
83+
84+
def is_geckodriver_on_path():
85+
paths = os.environ["PATH"].split(os.pathsep)
86+
for path in paths:
87+
if os.path.exists(path + '/' + "geckodriver"):
88+
return True
89+
return False
90+
91+
7692
def _add_chrome_proxy_extension(
7793
chrome_options, proxy_string, proxy_user, proxy_pass):
7894
""" Implementation of https://stackoverflow.com/a/35293284 for
@@ -474,6 +490,14 @@ def get_local_driver(
474490
options.add_argument('-headless')
475491
if LOCAL_GECKODRIVER and os.path.exists(LOCAL_GECKODRIVER):
476492
make_driver_executable_if_not(LOCAL_GECKODRIVER)
493+
elif not is_geckodriver_on_path():
494+
if not "".join(sys.argv) == "-c": # Skip if multithreaded
495+
from seleniumbase.console_scripts import sb_install
496+
sys_args = sys.argv # Save a copy of current sys args
497+
print("\nWarning: geckodriver not found."
498+
" Installing now:")
499+
sb_install.main(override="geckodriver")
500+
sys.argv = sys_args # Put back the original sys args
477501
firefox_driver = webdriver.Firefox(
478502
firefox_profile=profile,
479503
capabilities=firefox_capabilities,
@@ -540,6 +564,13 @@ def get_local_driver(
540564
extension_zip, extension_dir)
541565
if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
542566
make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
567+
elif not is_chromedriver_on_path():
568+
if not "".join(sys.argv) == "-c": # Skip if multithreaded
569+
from seleniumbase.console_scripts import sb_install
570+
sys_args = sys.argv # Save a copy of current sys args
571+
print("\nWarning: chromedriver not found. Installing now:")
572+
sb_install.main(override="chromedriver")
573+
sys.argv = sys_args # Put back the original sys args
543574
return webdriver.Chrome(options=chrome_options)
544575
except Exception as e:
545576
if headless:

0 commit comments

Comments
 (0)