Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python selenium clearing cache and cookies

Tags:

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

like image 884
Tyrell Avatar asked Oct 02 '17 16:10

Tyrell


People also ask

Does Selenium clear cache?

Selenium does not provide a way to delete cache, here are some workarounds. There are a few ways in which cache can be deleted using Selenium Webdriver for regular Chrome browsers. For instance, here they explain how selenium can be used to clear cache like a real user i.e., by navigating to chrome settings.

Can Selenium handle cookies?

Selenium WebDriver provides multiple commands for handling the cookies in a website. These Selenium cookies APIs provide you the required mechanism for interacting and querying the cookies. In Selenium Java, these methods are a part of the org. openqa.


1 Answers

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) 
like image 61
Wojciech Kuczer Avatar answered Sep 18 '22 14:09

Wojciech Kuczer