如何通过chromedriver硒禁用定位服务? [英] How to disable location service by chromedriver selenium?

查看:154
本文介绍了如何通过chromedriver硒禁用定位服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用硒2-Webdriver,Chromedriver,Java.我的一项测试需要关闭Chrome上的位置服务.

I'm using selenium 2 - Webdriver , Chromedriver, Java. One of my tests needs to turn off the location service on Chrome .

我注意到默认情况下,定位服务已打开Chromedriver.

I notice that by default, the location service is turned on Chromedriver.

我想知道是否可以通过chromedriver禁用位置服务吗?

I'm wondering if there is a way to disable location service on chromedriver?

非常感谢!

推荐答案

是的,有可能. 通过以下方式使用ChromeOptions类:

Yes, it's possible. Use the ChromeOptions class, in the following way:

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

您可以在此处 a>

这篇关于如何通过chromedriver硒禁用定位服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆