Python Selenium – How to Clear Cache and Cookies in Chrome WebDriver

pythonseleniumselenium-chromedriverselenium-webdriverwebdriver

I'm trying to clear the cache and cookies in my chrome browser (webdriver from selenium) but I can't find any solutions for specifically the chrome driver. How do I clear the cache and cookies in Python? Thanks!

Best Answer

Taken from this post:

For cookies, you can use the delete_all_cookies function:

driver.delete_all_cookies()

For cache, there isn't a direct way to do this through Selenium. If you are trying to make sure everything is cleared at the beginning of starting a Chrome driver, or when you are done, then you don't need to do anything. Every time you initialize a webdriver, it is a brand new instance with no cache, cookies, or history. Every time you terminate the driver, all these are cleared.

Related Question