Skip to content

Commit 4648094

Browse files
committed
Improve Microsoft EdgeDriver compatibility
1 parent ba51d51 commit 4648094

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

seleniumbase/console_scripts/sb_install.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ def make_executable(file_path):
8282
def main(override=None):
8383
if override == "chromedriver":
8484
sys.argv = ["seleniumbase", "install", "chromedriver"]
85-
if override == "geckodriver":
85+
elif override == "edgedriver":
86+
sys.argv = ["seleniumbase", "install", "edgedriver"]
87+
elif override == "geckodriver":
8688
sys.argv = ["seleniumbase", "install", "geckodriver"]
8789

8890
num_args = len(sys.argv)

seleniumbase/core/browser_launcher.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ def is_chromedriver_on_path():
8282
return False
8383

8484

85+
def is_edgedriver_on_path():
86+
paths = os.environ["PATH"].split(os.pathsep)
87+
for path in paths:
88+
if os.path.exists(path + '/' + "msedgedriver"):
89+
return True
90+
return False
91+
92+
8593
def is_geckodriver_on_path():
8694
paths = os.environ["PATH"].split(os.pathsep)
8795
for path in paths:
@@ -583,23 +591,39 @@ def get_local_driver(
583591
" executable: %s" % e)
584592
return webdriver.Ie(capabilities=ie_capabilities)
585593
elif browser_name == constants.Browser.EDGE:
586-
if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
587-
try:
588-
make_driver_executable_if_not(LOCAL_EDGEDRIVER)
589-
except Exception as e:
590-
logging.debug("\nWarning: Could not make edgedriver"
591-
" executable: %s" % e)
592-
# The new Microsoft Edge browser is based on Chromium
594+
try:
593595
chrome_options = _set_chrome_options(
594596
downloads_path, headless,
595597
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
596598
disable_csp, enable_sync, incognito, user_data_dir,
597599
extension_zip, extension_dir, servername, mobile_emulator,
598600
device_width, device_height, device_pixel_ratio)
601+
if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
602+
try:
603+
make_driver_executable_if_not(LOCAL_EDGEDRIVER)
604+
except Exception as e:
605+
logging.debug("\nWarning: Could not make edgedriver"
606+
" executable: %s" % e)
607+
elif not is_edgedriver_on_path():
608+
if not ("-n" in sys.argv or "".join(sys.argv) == "-c"):
609+
# (Not multithreaded)
610+
from seleniumbase.console_scripts import sb_install
611+
sys_args = sys.argv # Save a copy of current sys args
612+
print("\nWarning: chromedriver not found. Installing now:")
613+
sb_install.main(override="edgedriver")
614+
sys.argv = sys_args # Put back the original sys args
599615
return webdriver.Chrome(executable_path=LOCAL_EDGEDRIVER,
600616
options=chrome_options)
601-
else:
602-
return webdriver.Edge()
617+
except Exception as e:
618+
if headless:
619+
raise Exception(e)
620+
if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
621+
try:
622+
make_driver_executable_if_not(LOCAL_EDGEDRIVER)
623+
except Exception as e:
624+
logging.debug("\nWarning: Could not make edgedriver"
625+
" executable: %s" % e)
626+
return webdriver.Chrome(executable_path=LOCAL_EDGEDRIVER)
603627
elif browser_name == constants.Browser.SAFARI:
604628
arg_join = " ".join(sys.argv)
605629
if ("-n" in sys.argv) or ("-n=" in arg_join) or (arg_join == "-c"):

0 commit comments

Comments
 (0)