Teh Teh - 5 months ago 78
Python Question

Always Allow Geolocation in Firefox using Selenium

I am creating some end-to-end tests for a web app using Selenium.

I am working in Python and using the Firefox driver

driver = webdriver.Firefox()

The problem is that my web app using HTML5 geolocation, and it seems that everytime I run my tests, I have to click the 'Allow Location' popup in Firefox, making my tests less than automated.

Is there a way to force the Selenium Firefox driver to always allow geolocation without prompting?


I believe the default is to launch Firefox with a new, anonymous profile. You can launch selenium with -Dwebdriver.firefox.profile=whatever, where "whatever" is the name of a profile when you launch firefox -P.

To make sure there's no weirdness with persistent logins and other cookies:

  • Launch Firefox with "firefox -P"
  • Pick the profile you'll launch the tests with
  • Edit -> Preferences -> Privacy, select Use custom settings for history
  • Tell Firefox to keep cookies until "I close Firefox"