Tom J Muthirenthi
Tom J Muthirenthi

Reputation: 3340

Clear browser Cookies with Selenium WebDriver Java bindings

Does anyone know if it's possible to Clear Browser Cookies for WebDriver before starting the automation? (Note: Not Selenium RC)

Upvotes: 23

Views: 51330

Answers (3)

Monsignor
Monsignor

Reputation: 2947

ChromeDriver provides a way to clear cookies of all websites/domains:

driver.ExecuteChromeCommand("Storage.clearCookies", new Dictionary<string, object>())

Upvotes: 4

Guy
Guy

Reputation: 50819

Yes, it's possible

driver.manage().deleteAllCookies();

Call it right after you are creating the new WebDriver instance.

WebDriver driver = new ChromeDriver();
driver.manage().deleteAllCookies();

You can also delete the cookies one by one

Set<Cookie> allCookies = driver.manage().getCookies();
for (Cookie cookie : allCookies) {
    driver.manage().deleteCookieNamed(cookie.getName());
}

Upvotes: 46

Jyothishwar Deo
Jyothishwar Deo

Reputation: 436

Does this work for you?

driver.manage().deleteAllCookies();

Upvotes: 10

Related Questions