如何使用selenium默认启用地理位置?

ccrfmcuu  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(711)

这个问题在这里已经有答案了

如何在chromedriver中启用地理位置支持(7个答案)
24天前关门。
我正在编写测试用例来验证使用seleniumwebdriver的Map。当我试图打开Map使用网址然后位置警报弹出。

我想允许Map访问当前位置默认情况下,Map加载时没有位置警报。
我试过在chromeoptions中使用profile,但它不能满足我的要求。

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);

任何帮助都将不胜感激。

wpcxdonn

wpcxdonn1#

用途:

googlegeolocationaccess.enabled

请尝试:

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);

相关问题