How can I clear the cache of a new instance of a chromedriver in java? I am trying this but im not too sure what else to do? Would it be possible to create a javascript hack to clear the cache in JS which I can call from my driver?
private static WebDriver makeDriver() {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.manage().deleteAllCookies();
return driver;
}
By default, a completely clean profile with an empty cache, local storage, cookies is fired up by selenium. You are actually browsing privately with selenium.
First of all, there is a problem in your code - you are not passing your DesiredCapabilities
instance to the webdriver constructor (not tested though):
ChromeDriver driver = new ChromeDriver(capabilities);
You may also try forcing the "incognito" mode:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
capabilities.setCapability("chrome.switches", Arrays.asList("--incognito"));
ChromeDriver driver = new ChromeDriver(capabilities);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With