O'Reilly logo

Selenium Testing Tools Cookbook by Unmesh Gundecha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cleaning local and session storage

When tests are run on HTML5 applications using local or session storage, lots of local and session storage entries will be created. When running tests in batch on an already used environment, cleaning the local and session storage is a good idea before you begin your tests.

In this recipe, we will briefly see how to remove local or session storage items and clean the values.

How it works...

To remove a specific item from local or session storage, you can use the removeItem() method in the following way:

//To Remove a specific Key along with it's value
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("localStorage.removeItem(lastname);");

For session storage, the following code ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required