+91 9790664230
kumar.arun211@gmail.com

How to open URL in specific Firefox browser version

Blog to learn python and selenium

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:

1)


	System.setProperty("webdriver.gecko.driver", "Path_To_Firefox_Driver/geckodriver");
	System.setProperty("webdriver.firefox.bin", "Path_To_Firefox_Binary");
	WebDriver driver = new FirefoxDriver();
	driver.get("http://www.google.com");

2)


	FirefoxBinary firefoxBinary = new FirefoxBinary(new File("Path_To_Firefox_Binary"));
	DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
	desiredCapabilities.setCapability(FirefoxDriver.BINARY, firefoxBinary);
	WebDriver driver = new FirefoxDriver(desiredCapabilities);
	driver.get("http://www.google.com");

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

Steps:

  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. […] How to open URL in specific Firefox browser version […]

Leave a Reply

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

© 2018 Copyrights. All Rights Reserved. Arunkumar Velusamy