Last Updated: October 11, 2016
·
10.49K
· emanuelcoelho1986

Run Selenium with latest Firefox versions

It seems that to run the latest tests with Firefox we need to use marionette because they didn't sign Selenium Firefox driver extension (webdriver.xpi) and it's required according to lukeis. You can find more about this here https://github.com/SeleniumHQ/selenium/issues/2559

Wither way, this is an example of how I was able to fix the problem.

First of all I'm using:

  • MacOS Sierra
  • Python 3.5
  • Selenium 3 beta 3
  • I'm assuming you are familiar with Python and Selenium

I'm using Selenium 3 beta because I need to test Safari. Safari 10 provides the webdriver in order to use selenium, but we must use version 3 https://webkit.org/blog/6900/webdriver-support-in-safari-10

  • Step 1:
    • I did a quick search about Python 3.5, Selenium 3 and Firefox and I come across a bug in Selenium that you can easily fix by doing as they say here: http://www.vardump.pw/sc?id=is39527858
    • In a short description, you need to go to line 133 in the file webelement.py and change from raw = pkgutil.get_data(__package__, 'getAttribute.js') to raw = pkgutil.get_data(__package__, 'getAttribute.js').decode('utf8'). Mine was located at /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium-3.0.0b3-py3.5.egg/selenium/webdriver/remote/webelement.py
  • Step 2:
  • Step 3:
    • This is a piece of code as an example of what you need to test and make sure you can use Firefox with Selenium
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.FIREFOX

# Tell the Python bindings to use Marionette.
# This will not be necessary in the future,
# when Selenium will auto-detect what remote end
# it is talking to.
caps["marionette"] = True

# Path to Firefox DevEdition or Nightly.
# Firefox 47 (stable) is currently not supported,
# and may give you a suboptimal experience.
#
# On Mac OS you must point to the binary executable
# inside the application package, such as
# /Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin
caps["binary"] = "/Applications/Firefox.app/Contents/MacOS/firefox-bin"
geckodriver="/Users/pmarques/Test/geckodriver"

driver = webdriver.Firefox(capabilities=caps, executable_path="/Users/pmarques/Test/geckodriver")
driver.get("http://www.google.com")