26

I'm trying to clear the cache and cookies in my firefox browser but I can't get it to work. I have searched it up and i'm only getting solutions for java and C#. How do I clear the cache and cookies in Python?

selenium version: 3.6.0

platform: python

python version: 2.7.8

webdriver: geckodriver

browser platform: Firefox

Paulo Scardine
  • 73,447
  • 11
  • 124
  • 153
Tyrell
  • 896
  • 7
  • 15
  • 26

1 Answers1

57

For cookies use delete_all_cookies() function

driver.delete_all_cookies()

for cache create profile

profile = webdriver.FirefoxProfile()
profile.set_preference("browser.cache.disk.enable", False)
profile.set_preference("browser.cache.memory.enable", False)
profile.set_preference("browser.cache.offline.enable", False)
profile.set_preference("network.http.use-cache", False) 
driver = webdriver.Firefox(profile)
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Wojciech Kuczer
  • 631
  • 6
  • 6