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=<span class="hljs-string">"</span><span class="hljs-string">https://www.example.com"</span>;
driver.navigate().to(URL);
driver.manage().deleteCookieNamed(<span class="hljs-string">"foob"</span>);
}
Deleting all the cookies of the domain
@Test
public void deleteAllCookiesExample()
{
driver= new FirefoxDriver();
String URL=<span class="hljs-string">"</span><span class="hljs-string">https://www.example.com"</span>;
driver.navigate().to(URL);
driver.manage().deleteAllCookies();
}