使用Selenium Java处理边缘和野生动物园的位置弹出窗口
我正在尝试处理多个浏览器的Selenium Java的位置弹出窗口。我无法找到MS Edge和Safari的解决方案。我试图实现与以下浏览器相同的浏览器:
FirefoxProfile geoDisabled = new FirefoxProfile();
geoDisabled.setPreference("geo.enabled", false);
geoDisabled.setPreference("geo.provider.use_corelocation", false);
geoDisabled.setPreference("geo.prompt.testing", true);
geoDisabled.setPreference("geo.prompt.testing.allow", true);
caps.setCapability(FirefoxDriver.PROFILE,geoDisabled);
或在Chrome中为:
ChromeOptions chromeOptions = new ChromeOptions();
// SET CHROME OPTIONS
// 0 - Default, 1 - Allow, 2 - Block
int locationFlag = location.equals(true) ? 1:2;
Map< String, Object > prefs = new HashMap<>();
Map < String, Object > profile = new HashMap <> ();
Map < String, Object > contentSettings = new HashMap <> ();
contentSettings.put("geolocation", locationFlag);
profile.put("managed_default_content_settings", contentSettings);
prefs.put("profile", profile);
chromeOptions.setExperimentalOption("prefs", prefs);
更新: 以下解决方案为MSEDGE工作:
EdgeOptions edgeOptions = new EdgeOptions();
if(isPrivate) {
edgeOptions.addArguments("inprivate");
}
int locationFlag = location.equals(true) ? 1:2;
Map< String, Object > prefs = new HashMap<>();
Map < String, Object > profile = new HashMap <> ();
Map < String, Object > contentSettings = new HashMap <> ();
contentSettings.put("geolocation", locationFlag);
profile.put("managed_default_content_settings", contentSettings);
prefs.put("profile", profile);
edgeOptions.setExperimentalOption("prefs", prefs);
caps.merge(edgeOptions);
在Safari上仍然没有进展。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于边缘:
到目前为止,Safari不支持操纵位置prefs。
For edge:
Safari doesn't support as of now to manipulate location prefs.