How to open URL in specific Firefox browser version

The Blog To Learn Selenium and Test Automation

How to open URL in specific Firefox browser version

Often times we encounter a scenario where we need to run tests on different versions of Firefox browser on the same machine. This specific Firefox browser tests run using python selenium is possible and as easy as running tests in other scenarios using Selenium WebDriver.

In java, We can do it in two ways:


System.setProperty("webdriver.gecko.driver", "Path_To_Firefox_Driver/geckodriver");
System.setProperty("webdriver.firefox.bin", "Path_To_Firefox_Binary");
WebDriver driver = new FirefoxDriver();


FirefoxBinary firefoxBinary = new FirefoxBinary(new File("Path_To_Firefox_Binary"));
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setCapability(FirefoxDriver.BINARY, firefoxBinary);
WebDriver driver = new FirefoxDriver(desiredCapabilities);

Let’s see how can we do the same in Python.


  1. import FirefoxBinary module from selenium.webdriver.firefox.firefox_binary
  2. Create a new FirefoxBinary object, Firefox binary path as an argument
  3. Pass created FirefoxBinary object while creating Firefox webdriver
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('path/to/binary')
driver = webdriver.Firefox(firefox_binary=binary)

Usage 1:

Sometime we may want to run tests in older Firefox version or different versions of Firefox browser available in the same machine.

Usage 2:

Sometimes Firefox is not installed in default location and Selenium throws below exception

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.

Exception clearly states that Firefox is installed in some other location while Selenium WebDriver is trying to find Firefox and launch from default location but it couldn’t find.


One Response

  1. […] Open specific version of Firefox browser among many in same system […]

Leave a Reply

Your email address will not be published. Required fields are marked *