How to delete Cookies in Selenium Webdriver

Delete Cookie
Delete Cookie with Name
Delete All Cookies

User can delete a cookie from the browser's "cookie jar". The domain of the cookie will be ignored.

User can delete the named cookie from the current domain. This is equivalent to setting the named cookie's expiry date to sometime in the past.

User can also delete all the cookies for the current domain using driver.manage().deleteAllCookies();

Example:

Deleting the specific cookie with cookie name "--utmb"

@Test
	public void deleteCookieNamedExample()
	{
		driver= new FirefoxDriver();
		String URL="http://www.flipkart.com";
		driver.navigate().to(URL);
		driver.manage().deleteCookieNamed("__utmb");
	}

Deleting all the cookies of the domain

@Test
	public void deleteAllCookiesExample()
	{
		driver= new FirefoxDriver();
		String URL="http://www.flipcart.com";
		driver.navigate().to(URL);
		driver.manage().deleteAllCookies();
	}
Selenium Tutorials: 

Comments

After deleting cookies from selenium webdriver,how to verify that cookies deleted or not.

You can use get Cookies method(driver.manage().getCookies();) and check if they exist or not . You can also try to grt the cookie by it specific name.

How to delete cookies from IE by using Selenium with java ?

excellent. it is easy to learn and understand.

what is the use of thread in xml

Thread is used to run your test cases parallel in same browser at a time

How to clear all cookies in Internet Explorer 11 using Selenium WebDriver 2.50.0??

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.