1.重新打开一个新的浏览器
driver = new ChromeDriver();
2.用代码清空缓存
step.getWebDriver().manage().deleteAllCookies();
3.清空文件缓存
public static void clearTempFile() throws Exception {
try {
File objTempFolder = new File(System.getProperty("java.io.tmpdir"));
if (Constants.ISDEBUG) System.out.println(Constants.LogCustom + objTempFolder.getAbsolutePath().toString());
for (File objEach : objTempFolder.listFiles()) {
if (objEach.getName().toString().toLowerCase().contains("scoped_dir")) {
if (objEach.isDirectory()) {
FileUtils.delFile(objEach);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
4.打开浏览器清空缓存
step.getWebDriver().get("chrome://settings/clearBrowserData");
Thread.sleep(50);
Actions action = new Actions(step.getWebDriver());
action.sendKeys(Keys.RETURN).perform();
5.启用浏览器无无痕模式
ChromeOptions options = new ChromeOptions();
options.addArguments("–incognito");
driver = new ChromeDriver(options);
|