Skip to content

Commit 15d5a29

Browse files
committed
Add DRIVER_DIR to PATH for Selenium 4 compatibility
1 parent 25fe26f commit 15d5a29

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from seleniumbase import extensions # browser extensions storage folder
2121
urllib3.disable_warnings()
2222
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
23+
if DRIVER_DIR not in os.environ["PATH"]:
24+
os.environ["PATH"] += os.pathsep + DRIVER_DIR
2325
EXTENSIONS_DIR = os.path.dirname(os.path.realpath(extensions.__file__))
2426
DISABLE_CSP_ZIP_PATH = "%s/%s" % (EXTENSIONS_DIR, "disable_csp.zip")
2527
PROXY_ZIP_PATH = proxy_helper.PROXY_ZIP_PATH
@@ -464,16 +466,10 @@ def get_local_driver(
464466
options.add_argument('-headless')
465467
if LOCAL_GECKODRIVER and os.path.exists(LOCAL_GECKODRIVER):
466468
make_driver_executable_if_not(LOCAL_GECKODRIVER)
467-
firefox_driver = webdriver.Firefox(
468-
firefox_profile=profile,
469-
capabilities=firefox_capabilities,
470-
options=options,
471-
executable_path=LOCAL_GECKODRIVER)
472-
else:
473-
firefox_driver = webdriver.Firefox(
474-
firefox_profile=profile,
475-
capabilities=firefox_capabilities,
476-
options=options)
469+
firefox_driver = webdriver.Firefox(
470+
firefox_profile=profile,
471+
capabilities=firefox_capabilities,
472+
options=options)
477473
except WebDriverException:
478474
# Don't use Geckodriver: Only works for old versions of Firefox
479475
profile = _create_firefox_profile(
@@ -502,11 +498,7 @@ def get_local_driver(
502498
ie_capabilities = ie_options.to_capabilities()
503499
if LOCAL_IEDRIVER and os.path.exists(LOCAL_IEDRIVER):
504500
make_driver_executable_if_not(LOCAL_IEDRIVER)
505-
return webdriver.Ie(
506-
capabilities=ie_capabilities,
507-
executable_path=LOCAL_IEDRIVER)
508-
else:
509-
return webdriver.Ie(capabilities=ie_capabilities)
501+
return webdriver.Ie(capabilities=ie_capabilities)
510502
elif browser_name == constants.Browser.EDGE:
511503
if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
512504
make_driver_executable_if_not(LOCAL_EDGEDRIVER)
@@ -525,9 +517,7 @@ def get_local_driver(
525517
elif browser_name == constants.Browser.OPERA:
526518
if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER):
527519
make_driver_executable_if_not(LOCAL_OPERADRIVER)
528-
return webdriver.Opera(executable_path=LOCAL_OPERADRIVER)
529-
else:
530-
return webdriver.Opera()
520+
return webdriver.Opera()
531521
elif browser_name == constants.Browser.PHANTOM_JS:
532522
with warnings.catch_warnings():
533523
# Ignore "PhantomJS has been deprecated" UserWarning
@@ -542,18 +532,13 @@ def get_local_driver(
542532
extension_zip, extension_dir)
543533
if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
544534
make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
545-
return webdriver.Chrome(
546-
executable_path=LOCAL_CHROMEDRIVER, options=chrome_options)
547-
else:
548-
return webdriver.Chrome(options=chrome_options)
535+
return webdriver.Chrome(options=chrome_options)
549536
except Exception as e:
550537
if headless:
551538
raise Exception(e)
552539
if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
553540
make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
554-
return webdriver.Chrome(executable_path=LOCAL_CHROMEDRIVER)
555-
else:
556-
return webdriver.Chrome()
541+
return webdriver.Chrome()
557542
else:
558543
raise Exception(
559544
"%s is not a valid browser option for this system!" % browser_name)

0 commit comments

Comments
 (0)