Reputation: 51
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
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
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