Skip to content

Commit a6b4806

Browse files
committed
Improve Firefox WebDriver usability on Linux
1 parent 1fee1e9 commit a6b4806

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ def get_local_driver(
516516
options = webdriver.FirefoxOptions()
517517
if headless:
518518
options.add_argument('-headless')
519+
firefox_capabilities['moz:firefoxOptions'] = (
520+
{'args': ['-headless']})
519521
if LOCAL_GECKODRIVER and os.path.exists(LOCAL_GECKODRIVER):
520522
try:
521523
make_driver_executable_if_not(LOCAL_GECKODRIVER)
@@ -530,15 +532,20 @@ def get_local_driver(
530532
" Installing now:")
531533
try:
532534
sb_install.main(override="geckodriver")
533-
except Exception:
534-
print("\nWarning: Could not install geckodriver!")
535+
except Exception as e:
536+
print("\nWarning: Could not install geckodriver: "
537+
"%s" % e)
535538
sys.argv = sys_args # Put back the original sys args
536-
firefox_driver = webdriver.Firefox(
537-
firefox_profile=profile,
538-
capabilities=firefox_capabilities,
539-
options=options)
540-
except WebDriverException:
541-
# Skip Firefox options and try again
539+
if "linux" in PLATFORM or not headless:
540+
firefox_driver = webdriver.Firefox(
541+
firefox_profile=profile,
542+
capabilities=firefox_capabilities)
543+
else:
544+
firefox_driver = webdriver.Firefox(
545+
firefox_profile=profile,
546+
capabilities=firefox_capabilities,
547+
options=options)
548+
except Exception:
542549
profile = _create_firefox_profile(
543550
downloads_path, proxy_string, user_agent, disable_csp)
544551
firefox_capabilities = DesiredCapabilities.FIREFOX.copy()

0 commit comments

Comments
 (0)