How to enable geo location by default using Selenium?

Viewed 992

I'm writing test cases to validate the maps using Selenium webdriver. When I try to open the maps using url then location alert is popped up.

enter image description here

I want to allow the map to access the current location by default when the map is loaded without location alert.

I have tried using profile in the ChromeOptions but it is not satisfying my requirements.

Map<String, Object> prefs = new HashMap<String, Object>();
Map<String, Object> profile = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.geolocation", 1); // 1:allow 2:block
options.setExperimentalOption("prefs", prefs);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
webDriver = new ChromeDriver(capabilities);

Any help would be appreciated.

1 Answers

use:

 googlegeolocationaccess.enabled

Please try:

Map<String, Object> prefs = new HashMap<String, Object>();
Map<String, Object> profile = new HashMap<String, Object>();
prefs.put("googlegeolocationaccess.enabled", true);
prefs.put("profile.default_content_setting_values.geolocation", 1); // 1:allow 2:block
prefs.put("profile.default_content_setting_values.notifications", 1);
prefs.put("profile.managed_default_content_settings", 1);
options.setExperimentalOption("prefs", prefs);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
webDriver = new ChromeDriver(capabilities);
Related