user3832962
user3832962

Reputation: 51

Edit Cookies in selenium webdriver

How to edit the cookies in selenium webdriver.Can anybody please help me in this as i am unable to do so. The last solution left with me is to delete the previous one and add new cookie with modified data .Is there any direct way to edit the cookie in selenium webdriver

Upvotes: 4

Views: 9125

Answers (2)

Piotr Boho
Piotr Boho

Reputation: 2768

Cookie cookie = webDriver.manage().getCookieNamed("cookie_name");
webDriver.manage().deleteCookie(cookie);
webDriver.manage().addCookie(
  new Cookie.Builder(cookie.getName(), cookie.getValue() + "abc")
    .domain(cookie.getDomain())
    .expiresOn(cookie.getExpiry())
    .path(cookie.getPath())
    .isSecure(cookie.isSecure())
    .build()
);

Upvotes: 6

vins
vins

Reputation: 15370

There is no explicit way to edit a cookie. You need to delete the old one and create the new cookie with updated data.

Upvotes: 1

Related Questions