Does anyone know how to set the expiry date for a cookie using Selenium C# and why an extra character is added to the domain specified?
Any issues with Chrome? And is there a desired capabilities or user preference to be added?
cookie1Dictionary.Add("domain","somesite.com ")
cookie1Dictionary.Add("path", "/");
cookie1Dictionary.Add("expiry", expirationdate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fff'Z'"));
For some reason the expiry data is null after using the call to
driver.Manage().AllCookies.AddCookie(cookie1Dictionary);
I'm trying to bypass sso login....
So expiry is null and the domain is displayed as .somesites.com
it's adding an additional character
I expected to add the cookies with all data specified.
There are the following overloaded constructors for Cookie
:
public Cookie(string name, string value)
public Cookie(string name, string value, string path)
public Cookie(string name, string value, string path, DateTime? expiry)
public Cookie(string name, string value, string domain, string path, DateTime? expiry)
public Cookie(string name, string value, string domain, string path, DateTime? expiry, bool secure, bool isHttpOnly, string sameSite)
One way to add a cookie with selenium webdriver is the following:
Cookie cookie = new (name: "key",
value: "value",
domain: "stackoverflow.com",
path: "/",
expiry: DateTime.Today.AddDays(1),
secure: true,
isHttpOnly: true,
sameSite: "Strict");
driver.Manage().Cookies.AddCookie(cookie);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.