Skip to main content

I found another solution. For me this worked like a charm and it'sIf your driver implements WebStorage you can invoke

driver.getSessionStorage().clear();
driver.getLocalStorage().clear();

In order to make sure that the prettiest way.driver does implement WebStorage the idiom is

if (driver instanceof WebStorage) {
    WebStorage webStorage = (WebStorage)driver;
    webStorage.getSessionStorage().clear();
    webStorage.getLocalStorage().clear();
}

or better

if (!(driver instanceof WebStorage)) {
    throw new IllegalArgumentException("This test expects the driver to implement WebStorage");
}
WebStorage webStorage = (WebStorage)driver;
webStorage.getSessionStorage().clear();
webStorage.getLocalStorage().clear();

I found another solution. For me this worked like a charm and it's the prettiest way.

driver.getSessionStorage().clear();
driver.getLocalStorage().clear();

If your driver implements WebStorage you can invoke

driver.getSessionStorage().clear();
driver.getLocalStorage().clear();

In order to make sure that the driver does implement WebStorage the idiom is

if (driver instanceof WebStorage) {
    WebStorage webStorage = (WebStorage)driver;
    webStorage.getSessionStorage().clear();
    webStorage.getLocalStorage().clear();
}

or better

if (!(driver instanceof WebStorage)) {
    throw new IllegalArgumentException("This test expects the driver to implement WebStorage");
}
WebStorage webStorage = (WebStorage)driver;
webStorage.getSessionStorage().clear();
webStorage.getLocalStorage().clear();
Source Link

I found another solution. For me this worked like a charm and it's the prettiest way.

driver.getSessionStorage().clear();
driver.getLocalStorage().clear();