4

Following is my environment:

  1. OS : Windows 10 - 64 (Home edition)
  2. Browser : Firefox 47.0.1 (32 bit)
  3. Python : 2.7.10.12 (64 bit)
  4. selenium : 3.0.1
  5. Geckodriver: geckodriver-v0.11.1-win64.zip

Firefox is installed in C:\Program Files (x86)\Mozilla Firefox.

geckodriver.exe is placed in C:\Python27\Scripts location.

Following is my python code:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("http://www.python.org")

Which gives the following error:

Traceback (most recent call last):
  File "examples1.py", line 5, in <module>
    driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 152, in __init__
    keep_alive=True)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

My question is that though firefox is installed in default location, webdriver could not be able to find it and throws the error.

Note: when I explicitly specify the Firefox binary location as follows, it is working.

binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65

2 Answers2

0

The reason for this error is that Python couldn't find the function FirefoxBinary directly.

I encountered a similar problem. Solved it by giving reference to the function:

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

Later found that the solution is already available here (indirectly).

Community
  • 1
  • 1
  • I am not sure what the problem is. after restarting the machine, working as expected i..e., launched the browser from default location even without specifying the location using Firefox Binary location. I am sure it is not import problem. – Naveen Kumar R B Nov 02 '16 at 16:56
  • 2
    I have no idea what this means: "Python couldn't find the function FirefoxBinary directly"... but this answer is not correct. – Corey Goldberg Jan 13 '17 at 15:41
0

Restarting my machine solved the issue. (May be required if you keep the geckodriver.exe in one of the PATH locations.

Not sure if it was the real issue that needs to be solved, but one of the variable.


Little Background to geckodriver.exe and Firefox version support:

From geckodriver github page:

Firefox 47 is explicitly not supported

So, If you want to use Firefox 47.0.1 version, use Firefox driver but not geckodriver.

  1. In case of selenium 2.53, you don't need to do any additional things (no need to setup geckodriver as selenium 2.53 uses Firefox driver by default).
  2. In Selenium 3.0, we must set geckodriver path (as geckodriver is the default driver for Firefox in Selenium 3.0) using System.setProperty and set marionette to false, so geckodriver capabilities will be disabled and default Firefox driver is used.

example code:

System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe");
DesiredCapabilities d = new DesiredCapabilities();
d.setCapability("marionette", false);  // to disable marionette, by default true
WebDriver driver = new FirefoxDriver(d);

References:

  1. https://github.com/mozilla/geckodriver#supported-firefoxen
  2. https://github.com/mozilla/geckodriver/issues/224
  3. https://stackoverflow.com/a/40658421/2575259
Community
  • 1
  • 1
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65