How to disable location service by chromedriver selenium?

依然范特西╮ 提交于 2019-12-12 10:56:43

问题


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

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

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

many thanks in advance!


回答1:


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

You can see it as an answer for an issue here



来源:https://stackoverflow.com/questions/11808310/how-to-disable-location-service-by-chromedriver-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!