1

I need to use the most recent version of firefox on my Windows Computer. Hence dont want to use the default ghecko driver. Here is how close I got.

 import time
 from selenium import webdriver
 from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

 binary = webdriver.Firefox(executable_path= r'C:\Program Files\Mozilla Firefox\firefox.exe')
 caps = DesiredCapabilities.FIREFOX.copy()

 caps['marionette'] = True

 driver = webdriver.Firefox(firefox_binary=binary,capabilities=caps, executable_path=(os.path.abspath("geckodriver.exe")))

 time.sleep(5)
 driver.get("http://www.google.com")

The latest browser launches with default page however driver.get() doesnt work while exiting with a WebDriverException: Message: Service C:\Program Files\Mozilla Firefox\firefox.exe unexpectedly exited. Status code was: 1. How do I get around.

1 Answers1

1

You need to take care of a couple of things here:

  • The argument executable_path is used to pass the absolute path of the geckodriver binary.
  • If Firefox is installed at the default location you don't have to pass the absolute path of the firefox binary at all.
  • If you are using Selenium 3.x, GeckoDriver and Firefox, the capability marionette is set to true by default you don't have to explicitly mention that.
  • Inducing time.sleep() degrades the Test Execution Performance use WebDriverWait instead.
  • Your effective code block will be:

    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    
    binary = r'C:\Program Files\Mozilla Firefox\firefox.exe'
    options = Options()
    options.binary = binary
    cap = DesiredCapabilities().FIREFOX.copy()
    cap["marionette"] = True #optional
    driver = webdriver.Firefox(firefox_options=options, capabilities=cap, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
    driver.get("http://google.com/")
    print ("Firefox Initialized")
    driver.quit()
    
  • Console Output:

    Firefox Initialized
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352