ohbrobig ohbrobig - 10 months ago 163
Python Question

Disabling Cookies in Webdriver for Chrome/Firefox

I am trying to disable all cookies when starting up either the Chrome or Firefox browser. I have seen the examples on here but they're all in Java, and some of the Selenium code is different than it is for Python.

ChromeOptions options = new ChromeOptions();
Map prefs = new HashMap();
prefs.put("profile.default_content_settings.cookies", 2);
options.setExperimentalOptions("prefs", prefs);
driver = new ChromeDriver(options);

I want to do the above, just in Python.

Answer Source

It would be:

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("prefs", {"profile.default_content_settings.cookies": 2})

driver = webdriver.Chrome(chrome_options=chrome_options)

tested - worked for me (Chrome 45, selenium 2.47).