Setting Cookie in Selenium C#

Sometimes Cookies needs to be set in Selenium so that it automatically loads up a page with predefined values or something else.And Selenium has inbuilt functionality which allows to set Cookies in any language

//Setting Date and time of expiration and adding a cookie
DateTime time = new DateTime(2017, 03, 22, 23, 02, 03);
Cookie ck = new Cookie("COOKIE", "node1", "seleniumstutorial.com", "/", time);
Browser.Manage().Cookies.AddCookie(ck);

The above code allows you to set a Cookie using C# with Selenium

And the cookie method has 4 overloads namely

 

 

You may also like...