Disable geolocation in selenium-chromedriver with python

python-2.7, selenium-chromedriver, windows

Solution

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)

Problem

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.

Original source