// Go to the correct domain
driver.get("http://www.example.com");
// Now set the cookie. This
one's valid for the entire domain
Cookie cookie = new Cookie("key", "value");
driver.manage().addCookie(cookie);
// And now output all the
available cookies for the current URL
Set
allCookies = driver. manage().getCookies();
for (Cookie loadedCookie
: allCookies) {
System.out.println(String.format("%s -> %s",
loadedCookie.getName(), loadedCookie.getValue()));
}
// You can delete cookies in 3
ways
// By name
driver.manage().deleteCookieNamed("CookieName");
// By Cookie
driver.manage().deleteCookie(loadedCookie);
// Or all of them
driver.manage().deleteAllCookies();
No comments:
Post a Comment