How to enable cookie in phantomjsdriver selenium c#?

SeleniumAutomation TestingTesting Tools

We can enable cookie with Selenium Webdriver in C#. A cookie is the data stored by the browser. A key−value pair is used to store the information in cookies to hold the relevant information.

To add a cookie, the method AddCookie is used. The key and value of the cookie are passed as parameters to the method. Also, to obtain the cookie information, GetCookieNamed method is used.


driver.Manage().Cookies.AddCookie(new Cookie("Automation", "QA"));

For implementation we shall be using the NUnit framework.


using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
namespace NUnitTestProject1{
   public class Tests{
      String u = "";
      IWebDriver d;
      public void Setup(){
         //creating object of FirefoxDriver
         d = new FirefoxDriver();
      public void Test1(){
         //launching URL
         //adding cookie
         d.Manage().Cookies.AddCookie(new Cookie("Automation", "QA"));
         //obtain cookie
         var c = d.Manage().Cookies.GetCookieNamed("Automation");
      public void close_Browser(){


Click on Run All Tests button −

Click on Open additional output for this result link −

We should get the Test Outcome and Standard Output.

Published on 30-Jan-2021 12:08:10