Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox Build does not work with Selenium

for my research, I did some source code modifications in firefox and build it myself. In order to automate testing, I opted to use Selenium but unfortunately, my newly built Firefox seem to not support Selenium.

I did the following:

from selenium import webdriver from selenium.webdriver.firefox.firefox_binary import FirefoxBinary  binary = FirefoxBinary("/path/to/firefox/binary")  d = webdriver.Firefox(firefox_binary=binary)  d.get("http://www.google.de") 

The Firefox does open and is responsive (I can enter a website in the search bar). But after a while, the python script crashes with the following error message:

Traceback (most recent call last):   File "firefox.py", line 7, in <module>     d = webdriver.Firefox(firefox_binary=binary)   File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__     self.binary, timeout),   File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__     self.binary.launch_browser(self.profile)   File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser     self._wait_until_connectable()   File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 109, in _wait_until_connectable     raise WebDriverException("Can't load the profile. Profile " selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details. 

I did google that error message and most solutions suggested, that I should Update Selenium since it does not support the Firefox version used. Unfortunately, I installed the newest version of selenium (2.44.0) and I even used an older version of firefox (version 33) to rule out that point.

I also made sure that my code modifications are not the reason for this to crash by building a clean, unmodified firefox. Selenium doesn't work with this firefox either.

If I don't specify a firefox binary and let Selenium use the installed Firefox, everything works fine. So my guess is, that something is wrong with the firefox build, which I did exactly as mentioned in the online documentation (e.g. ./mach build).

Has anyone an idea, what my mistake might be? Any help is greatly appreciated!

Some setup information:

  • Firefox 33
  • Selenium 2.44.0
  • Python 3.4 (also tried 2.7, doesn't work either)
  • Firefox build with Ubuntu 14.04
like image 413
Thomas Müller Avatar asked Dec 05 '14 17:12

Thomas Müller


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.

Does Selenium work with Firefox?

Selenium IDE by SeleniumIt is implemented as a Firefox extension, and allows you to record, edit, and debug tests.

How do I use Firefox options in Selenium?

FirefoxOptions options = new FirefoxOptions(); driver = new RemoteWebDriver(new URL("http://10.x.x.x:4444/wd/hub"), options); When you start your Selenium Nodes, it displays a log information on using new FirefoxOptions preferred to 'DesiredCapabilities. firefox() along with all other browser options.

Which Firefox browser needs gecko driver?

Gecko driver works with Firefox version 47 or above. It can be resolved by updating Firefox version to 47 or above.


2 Answers

Ubuntu 14.04, firefox 36.0, selenium 2.44.0. The same problem, was solved by:

sudo pip install -U selenium 

Selenium 2.45.0 is OK with FF36.

update: Selenium 2.53+ is compatible with FF45

You can get older FF versions here

like image 100
zesaver Avatar answered Oct 14 '22 13:10

zesaver


I have spent a long time debugging this and ultimately gave up trying to make incompatible versions of selenium/firefox work. I just don't have the expertise in firefox to go any further. My recommendation is downloading stable versions from https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/ and keep trying combinations of firefox/selenium that work for your environment. For me, this is:

firefox==32.0.3 selenium==2.43.0

I'm referring to the changelog here: http://selenium.googlecode.com/git/java/CHANGELOG to see which versions are supposedly compatible.

Basically, what is happening is webdriver is polling on its port until it can establish a socket connection.

def _wait_until_connectable(self):     """Blocks until the extension is connectable in the firefox."""     count = 0     while not utils.is_connectable(self.profile.port):         if self.process.poll() is not None:             # Browser has exited             raise WebDriverException("The browser appears to have exited "                   "before we could connect. If you specified a log_file in "                   "the FirefoxBinary constructor, check it for details.")         if count == 30:             self.kill()             raise WebDriverException("Can't load the profile. Profile "                   "Dir: %s If you specified a log_file in the "                   "FirefoxBinary constructor, check it for details.")         count += 1         time.sleep(1)     return True 

And then if there is an socket error, keep going. So what you are probably seeing (at least what I am) is the browser hanging for 30 secs.

def is_connectable(port):     """     Tries to connect to the server at port to see if it is running.      :Args:      - port: The port to connect.     """     try:         socket_ = socket.socket(socket.AF_INET, socket.SOCK_STREAM)         socket_.settimeout(1)         socket_.connect(("127.0.0.1", port))         socket_.close()         return True     except socket.error:         return False 

Bleh. Alright, well I finally just decided to store the specific version I want and switch to the compatible selenium version.

bin_dir = os.path.join(const.WEBDRIVER_DIR, 'firefox', 'binary', '32.0.3', 'linux-x86_64', 'firefox') binary = FirefoxBinary(firefox_path=bin_dir) driver = webdriver.Firefox(firefox_binary=binary) 

I also highly recommend adding a log file to the firefox binary and checking that. Your issue might be unique and any bizarre errors will be logged there:

log_dir = os.path.join(const.LOGS_DIR, 'firefox')     try:     os.makedirs(directory) except OSError, e:     if e.errno == errno.EEXIST and os.path.isdir(directory):         pass log_path = os.path.join(log_dir, '{}.log'.format(datetime.datetime.now().isoformat('_')) log_file = open(log_path, 'w') binary = FirefoxBinary(firefox_path=bin_dir, log_file=log_file) 
like image 39
Justin Avatar answered Oct 14 '22 15:10

Justin