Amit
Amit

Reputation: 34793

How to delete cookies?

I want to delete cookies programmatically.

More specifically, I am using HtmlUnit with Java to automate browser operations. After performing some operations I want to clear cookies so that my subsequent operations make sense. How can I clear cookies through HtmlUnit or through Java or through any other way automatically.

Upvotes: 2

Views: 3897

Answers (3)

Amit
Amit

Reputation: 34793

In actual, the cookies in HtmlUnit doesn't get stored on disk until saved programmatically. They remain in the memory. From the memory they gets deleted when the HtmlUnit session expires.

Upvotes: 2

Ravi Vanapalli
Ravi Vanapalli

Reputation: 9950

You can user javascript code to expire your cookie using Now to expire it immediately

document.cookie = name + "=; " + Now + "; path=/";

syntax for creating cookie

document.cookie = "name=value; expires=date; path=path; domain=domain; secure";

Upvotes: 1

Drew Wills
Drew Wills

Reputation: 8446

Can you use the CookieManager?

This class appears to have methods for clearing all cookies or removing them individually.

Upvotes: 2

Related Questions