Reputation: 3340
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
Reputation: 2947
ChromeDriver
provides a way to clear cookies of all websites/domains:
driver.ExecuteChromeCommand("Storage.clearCookies", new Dictionary<string, object>())
Upvotes: 4
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
Reputation: 436
Does this work for you?
driver.manage().deleteAllCookies();
Upvotes: 10