Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable location service by chromedriver selenium?

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!

like image 619
user1488025 Avatar asked Aug 04 '12 11:08

user1488025


1 Answers

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

like image 166
Johnny Avatar answered Sep 21 '22 15:09

Johnny