0

Trying to disable the Geolocation prompt of Firefox where it asks for the permission to locate the user. I have read many posts in the internet and tried different things but it does not work. Firefox asks me everytime for a permission. I want to automate the test and I do not work to allow it everytime.

My current code:

FirefoxProfile fireFoxProfile = new FirefoxProfile("firefoxProfile");
fireFoxProfile.SetPreference("geo.prompt.testing", true);
fireFoxProfile.SetPreference("geo.prompt.testing.allow", true);
FirefoxOptions firefoxOptions = new FirefoxOptions() {
                Profile = firefoxProfile
            };
fireFoxDriver = new FirefoxDriver(geckoDriverPath, firefoxOptions);
La0x1
  • 145
  • 1
  • 2
  • 11

1 Answers1

0

You missed one more preference. This will allow the geolocation by default and will not prompt during test.

FirefoxProfile fireFoxProfile = new FirefoxProfile("firefoxProfile");
fireFoxProfile.SetPreference("geo.enabled", true);
fireFoxProfile.SetPreference("geo.prompt.testing", true);
fireFoxProfile.SetPreference("geo.prompt.testing.allow", true);
FirefoxOptions firefoxOptions = new FirefoxOptions() {
                Profile = firefoxProfile
            };
fireFoxDriver = new FirefoxDriver(geckoDriverPath, firefoxOptions);
Navarasu
  • 8,209
  • 2
  • 21
  • 32
  • It does not work. Copied it exactly and Firefox still asks me for the permission. – La0x1 Nov 02 '18 at 16:27
  • Actually i have checked in java binding. I am able to reproduce the issue. Then adding the preference solved for me. I have use this site for verification. https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation. Let me check c#. – Navarasu Nov 02 '18 at 17:36