如何使用selenium在chrome内容设置的位置添加允许站点

如何使用selenium在chrome内容设置的位置添加允许站点,selenium,selenium-chromedriver,selendroid,Selenium,Selenium Chromedriver,Selendroid,我想使用selenium在移动chrome上添加站点“a.com”。 选项-[高级内容设置位置在访问允许站点之前询问] 因为我想在我的测试中去掉弹出窗口 有人知道吗?要禁用chrome询问位置,您需要使用ChromeOptions并从配置文件设置中禁用geolocation ChromeOptions options = new ChromeOptions(); JSONObject jsonObject = new JSONObject(); jsonObject.put("prof

我想使用selenium在移动chrome上添加站点“a.com”。 选项-[高级内容设置位置在访问允许站点之前询问]

因为我想在我的测试中去掉弹出窗口


有人知道吗?

要禁用chrome询问位置,您需要使用
ChromeOptions
并从配置文件设置中禁用
geolocation

 ChromeOptions options = new ChromeOptions();

 JSONObject jsonObject = new JSONObject();
 jsonObject.put("profile.default_content_settings.geolocation", 2);

 options.setExperimentalOption("prefs", jsonObject);
 WebDriver driver = new ChromeDriver(options);
请注意,整个答案已经在SO帖子中解释过了

编辑:如果该选项保持启用状态,您只需更改此行即可

jsonObject.put("profile.default_content_settings.geolocation", 2);


要禁用chrome请求位置,您需要使用配置文件设置中的
ChromeOptions
并禁用
geolocation

 ChromeOptions options = new ChromeOptions();

 JSONObject jsonObject = new JSONObject();
 jsonObject.put("profile.default_content_settings.geolocation", 2);

 options.setExperimentalOption("prefs", jsonObject);
 WebDriver driver = new ChromeDriver(options);
请注意,整个答案已经在SO帖子中解释过了

编辑:如果该选项保持启用状态,您只需更改此行即可

jsonObject.put("profile.default_content_settings.geolocation", 2);


下面的代码片段用于禁用该弹出窗口。而不是配置文件。默认内容设置。地理位置

我使用了
profile.default\u content\u setting\u value.notifications

ChromeOptions options = new ChromeOptions();

JSONObject jsonObject = new JSONObject();
jsonObject.put("profile.default_content_setting_values.notifications", 1);

options.setExperimentalOption("prefs", jsonObject);
WebDriver driver = new ChromeDriver(options);

DesiredCapabilities=新DesiredCapabilities();
ChromeOptions选项=新的ChromeOptions();
Map prefs=新的HashMap();
prefs.put(“profile.default\u content\u settings.popups”,0);
prefs.put(“profile.default\u content\u setting\u values.notifications”,1);
选项。设置实验选项(“prefs”,prefs);
caps.setCapability(ChromeOptions.CAPABILITY,选项);

下面的代码片段可以帮助我禁用该弹出窗口。而不是配置文件。默认内容设置。地理位置

我使用了
profile.default\u content\u setting\u value.notifications

ChromeOptions options = new ChromeOptions();

JSONObject jsonObject = new JSONObject();
jsonObject.put("profile.default_content_setting_values.notifications", 1);

options.setExperimentalOption("prefs", jsonObject);
WebDriver driver = new ChromeDriver(options);

DesiredCapabilities=新DesiredCapabilities();
ChromeOptions选项=新的ChromeOptions();
Map prefs=新的HashMap();
prefs.put(“profile.default\u content\u settings.popups”,0);
prefs.put(“profile.default\u content\u setting\u values.notifications”,1);
选项。设置实验选项(“prefs”,prefs);
caps.setCapability(ChromeOptions.CAPABILITY,选项);

使用chrome devtools协议可以做到这一点。允许在访问目标网站之前配置地理位置权限。您可以查看我的另一个答案以了解更多详细信息。

使用chrome devtools协议可以做到这一点。允许在访问目标网站之前配置地理位置权限。您可以查看我的另一个答案以了解更多详细信息。

您好,欢迎来到stack overflow。有关如何提问和相应更新问题的更多详细信息,请参阅链接。您好,欢迎使用stack overflow。有关如何提问和相应更新问题的更多详细信息,请参阅链接。OP的问题是关于
添加允许站点
:),但您的代码正在禁用它。谢谢你的回答。我能再问一个吗?“prefs”仅适用于桌面Chrome。在移动Chrome上我该怎么办?@DebanjanB OP谈到了
去掉我测试中的弹出窗口
,这让我相信他想忽略/禁用此功能。@LeBronPark你可以使用移动仿真来实现这一点。是相同的链接。@demouser123您是对的(+1)您能帮我设置它
允许
(始终)?ThanksOP的问题是关于
添加允许站点
:),但您的代码正在禁用它。谢谢你的回答。我能再问一个吗?“prefs”仅适用于桌面Chrome。在移动Chrome上我该怎么办?@DebanjanB OP谈到了
去掉我测试中的弹出窗口
,这让我相信他想忽略/禁用此功能。@LeBronPark你可以使用移动仿真来实现这一点。是相同的链接。@demouser123您是对的(+1)您能帮我设置它
允许
(始终)?谢谢