【问题标题】:How to enable geo location by default using Selenium? [duplicate]如何使用 Selenium 默认启用地理位置? [复制]
【发布时间】:2020-12-13 10:31:20
【问题描述】:

我正在编写测试用例以使用 Selenium webdriver 验证地图。当我尝试使用 url 打开地图时,会弹出位置警报。

我想在加载地图时默认允许地图访问当前位置而没有位置警报。

我曾尝试在 ChromeOptions 中使用配置文件,但它不能满足我的要求。

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

任何帮助将不胜感激。

【问题讨论】:

  • 当然不是,我不想填充弹窗,网站需要使用当前的地理位置。

标签: java selenium geolocation selenium-chromedriver


【解决方案1】:

使用:

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

【讨论】:

  • 感谢您的解决方案,但似乎无法在隐身模式下工作。
  • 它是否在正常模式下工作,点火模式可能不允许它,因为这是使用它的原因之一
  • 是的,它在正常模式下工作
  • @light_ray 你能试试更新的答案吗,请投票并接受它帮助的问题
猜你喜欢
  • 2016-01-10
  • 1970-01-01
  • 2017-05-21
  • 1970-01-01
  • 2021-09-12
  • 2021-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多