简体   繁体   中英

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;
}

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM