Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Clear IE Cache of Selenium Web Driver

Usually you want a fresh session without old cashing data and without any old cookies when you start a new run of your Selenium tests. For example if you are testing an online shop an in your last test you have put some products in your basket, you probably don’t want when you start your next test a pop up showing up that asks you “You still have products in your basket, do you want to keep them there?”

The Chrome and Firefox Webdriver already starts with a clear session by default when creating a new instance. Unfortunately the Internet Explorer WebDriver doesn’t.

You can force the IE Web Driver though to start with a clear session with empty cache and no cookies stored. To do this you need to initialize the IE WebDriver instance using DesiredCapabilities like this:

DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);

WebDriver iEWebDriver = new InternetExplorerDriver(capabilities);

The most simple Selenium program using those DesiredCapabilites, would then look like this:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class RunTest {
	public static void main(String[] args) {
				"C:/Users/Nils/Programm Daten/Eclipse Libs/WebDriver/IEDriverServer_x64_2.44.0/IEDriverServer.exe");

		// Setting IE to clean session
		DesiredCapabilities capabilities = DesiredCapabilities
				InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);

		WebDriver iEWebDriver = new InternetExplorerDriver(capabilities);


This post first appeared on FRET, please read the originial post: here

Share the post

Clear IE Cache of Selenium Web Driver


Subscribe to Fret

Get updates delivered right to your inbox!

Thank you for your subscription