Java 如何允许使用Selenium进行位置访问?
我试图在Java中使用Selenium来获取用户的地理坐标,但是使用IP地址不够准确,所以我想使用这个网站,但它不起作用,我猜这是因为你必须允许使用位置,所以我可以在Selenium中使用位置,或者通过其他方式获取准确的地理坐标通常,当站点想要获取此类数据时,浏览器会询问您是否要共享您的位置。问题在弹出窗口中,无法用Java 如何允许使用Selenium进行位置访问?,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我试图在Java中使用Selenium来获取用户的地理坐标,但是使用IP地址不够准确,所以我想使用这个网站,但它不起作用,我猜这是因为你必须允许使用位置,所以我可以在Selenium中使用位置,或者通过其他方式获取准确的地理坐标通常,当站点想要获取此类数据时,浏览器会询问您是否要共享您的位置。问题在弹出窗口中,无法用selenium控制。在这种情况下,您需要告诉浏览器,不要打开弹出窗口,同时允许共享您的位置,这样弹出窗口一开始就不会被打开 对于Firefox,您需要: 打开站点 允许共享您的位
selenium
控制。在这种情况下,您需要告诉浏览器,不要打开弹出窗口,同时允许共享您的位置,这样弹出窗口一开始就不会被打开
对于Firefox
,您需要:
- 打开站点
- 允许共享您的位置(您也可以检查
查看设置)about:permissions
- 保存当前的firefox配置文件
- 启动firefox时,
指向您以前保存的配置文件FirefoxProfile
有什么方法可以用HtmlUnitDriver实现吗?比如说一些有驱动能力的东西
FirefoxOptions opt = getFirefoxOptions();
WebDriver webDriver = new FirefoxDriver(opt);
//method for fire fox profile//////////////////////////////////
public static FirefoxProfile getFirefoxProfile() {
ProfilesIni profileIni = new ProfilesIni();
FirefoxProfile profile = profileIni.getProfile("webDriverProfile");
System.out.println("profile is null : " + (profile == null));
if (profile == null) {
profile = new FirefoxProfile();
}
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", "download/path");
profile.setPreference(
"browser.helperApps.neverAsk.saveToDisk",
"application/pdf,application/octet-stream,"
+ "application/download,text/html,application/xhtml+xml");
profile.setPreference("pdfjs.disabled", true);
// profile.setPreference("dom.webnotifications.enabled", true);
profile.setPreference("geo.enabled", true);
profile.setPreference("geo.provider.use_corelocation", true);
profile.setPreference("geo.prompt.testing", true);
profile.setPreference("geo.prompt.testing.allow", true);
profile.setPreference("geo.wifi.uri", "path-to-loglatjson\\geo-location-ITPL.json");
// profile.setPreference("browser.helperApps.neverAsk.openFile",
// "application/pdf");
// profile.setPreference("browser.helperApps.alwaysAsk.force", false);
/*
* profile.setPreference("browser.download.manager.alertOnEXEOpen",
* false);
* profile.setPreference("browser.download.manager.focusWhenStarting",
* false); profile.setPreference("browser.download.manager.useWindow",
* false);
* profile.setPreference("browser.download.manager.showAlertOnComplete",
* false);
* profile.setPreference("browser.download.manager.closeWhenDone",
* false);
*/
return profile;
}