Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chromedriver clear cache - java

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;
}
like image 572
Ben Avatar asked Nov 04 '15 18:11

Ben


1 Answers

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);
like image 106
alecxe Avatar answered Sep 20 '22 14:09

alecxe