Default

How to delete Cookies in Selenium

How to delete Cookies in Selenium

Users 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. Users can also delete all the cookies for the current domain using the driver.manage().deleteAllCookies() method.

Examples

Deleting the specific cookie with the cookie name “foo”

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

Deleting all the cookies of the domain

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