简体   繁体   English

chromedriver clear cache - java

[英]chromedriver clear cache - java

How can I clear the cache of a new instance of a chromedriver in java? 如何在java中清除chromedriver的新实例的缓存? 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? 是否有可能创建一个javascript hack来清除JS中的缓存,我可以从我的驱动程序调用?

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 . 默认情况下, 具有空缓存,本地存储,cookie的完全干净的配置文件由selenium启动 You are actually browsing privately with selenium. 你实际上正在私下浏览 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): 首先,您的代码中存在一个问题 - 您没有将DesiredCapabilities实例传递给webdriver构造函数(尽管未经过测试):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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