9

I'm having a problem with firefox caching, when i change a site redirection firefox decides that it needs to cache this.

The point is I wan't to create a test that tests editing a redirection works, but this caching prevents me from doing this.

Is there a way to disable firefox caching? or better yet delete it when needed?

NOTE: It's not cookies but the actual firefox cache.

I'm using webdriver C# version.

crthompson
  • 15,653
  • 6
  • 58
  • 80
Martin Mussmann
  • 697
  • 2
  • 9
  • 20

2 Answers2

6

Take a look at this page: http://code.google.com/p/selenium/issues/detail?id=40

To disable Firefox caching you can try: Create a new profile with firefox.exe -ProfileManager

Go to the Firefox profile directory and add the following to prefs.js:

user_pref("browser.cache.disk.enable", false);
user_pref("browser.cache.memory.enable", false);
user_pref("browser.cache.offline.enable", false);
user_pref("network.http.use-cache", false);

Tell Selenium to use the custom Firefox profile (This is Java):

ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("Selenium");
FirefoxDriver browser = new FirefoxDriver(profile);
Zane
  • 2,890
  • 2
  • 24
  • 23
  • 1
    This answer helped me a lot as I was having the same issues with Ruby and Watir so I adapted this solution for my use case, in the following way: 1) No need to create a custom firefox profile and to make changes to "pref.js", 2) Set the cache preferences for the current profile directly in the ruby script with, for example: `profile["browser.cache.disk.enable"] = false `. This is only one of the four cache settings, but the syntax is of course the same for all of them. – Redoman Jul 08 '20 at 14:06
4

To disable chrome caching:

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-application-cache')
driver = webdriver.Chrome(chrome_options=chrome_options)

List of available command-line arguments you can see here.

Serge
  • 1,947
  • 3
  • 26
  • 48