Opening browser with cache disabled


I need that when a new session of the browser is started, the cache is disabled. Manually, I achieve that by going to the Network tab of the developer tools and checking the box to disable cache:

I tried to run the automated tests with incognito but it doesn’t work. Is there any desired capability or browser preference I can set to achieve this? I need this both for Firefox and Chrome.

Thank you!

What happens when you try searching other forums first?


Thank you for the reference. I tried and it doesn’t work.

I have this initial portion of code before calling the WebUI.openBrowser():

I first tried "applicationCacheEnabled: false and it didn’t work, and then tried those last for entries and also doesn’t work.

I also tried this approach after doing WebUI.openBrowser()

        WebDriver driver = DriverFactory.getWebDriver();
        driver.findElement(By.cssSelector("* /deep/ #clearBrowsingDataConfirm")).click();

And it didn’t work either.

I checked the ID of the button to delete cookies and it’s correct. Even tried the following with no success: driver.findElement("#clearBrowsingDataConfirm")).click();

Also this solution doesn’t suit me because it appears to apply only to Chrome browser and I need it to work in Firefox as well.

Setting DesiredCapabilities on the ChromeProfile, before opening the browser, didn’t work?!

What I usually do is what I showed about, I set web driver preferences with RunConfiguration. It worked for other things such as changing the default download path of files or opening in incognito.
The desired capabilities approach is not my preferred one because I need this to work for Chrome, Firefox, Firefox headless and Chrome headless, so I’d have to write code for each one of this browsers.

In any case I just tried this before doing the opening of browser:

DesiredCapabilities cap =
cap.setCapability("applicationCacheEnabled", false)

and it didn’t work as well. I am not even sure if the WebUI.openBrowser() picks up the capabilities I just set because in the example from that page, it’s necessary to pass the capabilities to the web driver constructor.

Hi @joana.pedroso,
You may want to review this posting by @Brandon_Hein.

Also if you do a forum search for ‘Desired Capabilities’ you should find a lot of helpful postings.

Good luck!

1 Like

Thanks for this share! But should I be the person it be directed at?

Sorry picked wrong person, fixed.


I tried that approach and it’s not working. I did a reply there to see if the author can contribute with some ideas.

Thank you for the link!

Did it work for Chrome? Also, what does your code look like when you apply it for that use case?

If it works for Chrome, you may be able to come up with a strategy pattern to handle this. Yes, that will require you to know how to code…

We’ll be here to help you code the solution…


I gave up trying to implement this because meanwhile the problem that was making login only possible with the cache disabled was solved.

Thank you!

1 Like