Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't open browser with Selenium after Firefox update

I use Selenium WebDriver on Ubuntu Desktop 16.04, and I can't open browser. I get the following error after Firefox update (before this, it all worked):

Traceback (most recent call last):   File "test.py", line 6, in <module>     driver = webdriver.Firefox()   File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 81, in __init__     self.binary, timeout)   File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__     self.binary.launch_browser(self.profile, timeout=timeout)   File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser     self._wait_until_connectable(timeout=timeout)   File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable     raise WebDriverException("The browser appears to have exited " selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details. 
like image 966
Alexa Iulian Avatar asked Jun 11 '16 08:06

Alexa Iulian


People also ask

Which version of Firefox is compatible with Selenium?

New Selenium IDE FireFox was fully supported only in previous versions i.e. v47 and earlier. Selenium WebDriver version 2.53 is not compatible with Mozilla FireFox version 47.0+. After v47. 0, FireFox is provided with GeckoDriver.

How do I get my browser back in Selenium?

The respective command that takes you back by one page on the browser's history can be written as: driver. navigate(). back();

How do I open Selenium in Firefox?

To make Firefox work with Python selenium, you need to install the geckodriver. The geckodriver driver will start the real firefox browser and supports Javascript. Take a look at the selenium firefox code. First import the webdriver, then make it start firefox.

Does Selenium work with Firefox?

Mozilla Firefox is one of the most widely used browsers in the world. It has enhanced features and is supported by a multitude of the latest testing tools and techniques. One such tool is Selenium. Selenium uses Firefox Driver to link the test cases with the Firefox browser.


2 Answers

As of Firefox version 47.0 (which came out a little while a go), a new driver must be used (created by mozilla instead of selenium) to connect to Firefox, because of a bug introduces in this version. As of Firefox version 48.0 the old driver will be deprecated completely and only Marionette can be used so it is better to switch now. See: Marionette Webdriver for Firefox

Download the driver (in OSX just use brew install geckodriver), rename the executable to wires.exe on windows, or wires on *nix systems, and make sure the executable is present in your system path, then use this driver in your program instead of the old driver by using the following:

When using a local webdriver:

Python:

firefox_capabilities = DesiredCapabilities.FIREFOX firefox_capabilities['marionette'] = True  driver = webdriver.Firefox(capabilities=firefox_capabilities) 

Ruby:

driver = Selenium::WebDriver.for :firefox, marionette: true 

Javascript:

var capabilities = Capabilities.firefox(); capabilities.set('marionette', true);  var driver = new webdriver.Builder().withCapabilities(capabilities).build(); 

Java:

DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("marionette", true); Webdriver driver = new FirefoxDriver(capabilities); 

C#:

var driver = new FirefoxDriver(new FirefoxOptions()); 

When using selenium grid:

When using a selenium grid the driver should be present in the path for all machines in your grid.

Python:

firefox_capabilities = DesiredCapabilities.FIREFOX firefox_capabilities['marionette'] = True driver = webdriver.Firefox(capabilities=firefox_capabilities) 

Ruby:

caps = Selenium::WebDriver::Remote::Capabilities.firefox marionette: true driver = Selenium::WebDriver.for :firefox, desired_capabilities: caps 

Java:

DesiredCapabilities capabilities = DesiredCapabilities.firefox(); // Set Marionette on so the Grid will use this instead of normal FirefoxDriver capabilities.setCapability("marionette", true);  WebDriver driver = new RemoteWebDriver(capabilities);  

C#:

DesiredCapabilities capabilities = DesiredCapabilities.Firefox(); // Set Marionette on so the Grid will use this instead of normal FirefoxDriver capabilities.SetCapability("marionette", true);  var driver = new RemoteWebDriver(capabilities);  
like image 121
Mobrockers Avatar answered Sep 28 '22 01:09

Mobrockers


FIXED: Solution at this time is to downgrade Firefox! run this command to get a list of available Firefox versions.

apt-cache show firefox | grep Version 

My Result:

Version: 47.0+build3-0ubuntu0.16.04.1 Version: 45.0.2+build1-0ubuntu1 

Install:

sudo apt-get install firefox=45.0.2+build1-0ubuntu1 

To keep this version and disallow updates:

sudo apt-mark hold firefox 

If you want to unhold firefox version and allow updates:

sudo apt-mark unhold firefox sudo apt-get upgrade 
like image 29
Alexa Iulian Avatar answered Sep 28 '22 03:09

Alexa Iulian