gpt4 book ai didi

java - 如何使用 Selenium 默认启用地理位置?

转载 作者:行者123 更新时间:2023-12-04 08:25:44 25 4
gpt4 key购买 nike

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





How do I enable geolocation support in chromedriver?

(9 个回答)


1年前关闭。




我正在编写测试用例来验证使用 Selenium webdriver 的 map 。当我尝试使用 url 打开 map 时,会弹出位置警报。
enter image description here
我想在没有位置警报的情况下加载 map 时默认允许 map 访问当前位置。
我曾尝试在 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);
任何帮助,将不胜感激。

最佳答案

采用:

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

关于java - 如何使用 Selenium 默认启用地理位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65274570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com