urinella
urinella

Reputation: 41

Disable geolocation in selenium-chromedriver with python

Want to disable automatic geoloaction in Chrome using Chromedriver when I visit a https website.

Tryed:

from selenium.webdriver.chrome.options import Options
chromeOptions = webdriver.ChromeOptions()
prefs = {"profile.default_content_settings.geolocation" : "2"}
chromeOptions.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)

And:

from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=chrome_options)

Both doesn't work because on every new chrome window created with chromedriver the geolocation is enabled.

Upvotes: 4

Views: 7948

Answers (2)

Rick Richard
Rick Richard

Reputation: 27

Below code is working for me on July 2018

    ChromeOptions options = new ChromeOptions();
    Map<String, Object> prefs = new HashMap<String, Object>();
    prefs.put("profile.managed_default_content_settings.geolocation", 2);
    options.setExperimentalOption("prefs", prefs);
    ChromeDriver = new ChromeDriver(options);

Saludos.

Upvotes: 1

saurabh baid
saurabh baid

Reputation: 1877

your pref key is incorrect, below code worked for me

options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.geolocation" :2}
options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=options)

Upvotes: 10

Related Questions