How to enable cookie in phantomjsdriver selenium c#?

Following is my code :

case BrowserType.PhantomJS:
               var service = PhantomJSDriverService.CreateDefaultService(Path.Combine(_rootPath, @"Packages\"));
               var cookieFilePath=Path.Combine(_rootPath, @"Packages\cookie.txt");
                 if (!File.Exists(cookieFilePath))

                 var phantomjsoptions = new PhantomJSOptions();
                 driver = new PhantomJSDriver(service,phantomjsoptions);
                 var cookieJar = driver.Manage().Cookies;
                 cookieJar.AddCookie(new Cookie("x", "12345"));
                 return driver;

Basically the issue is that i am not able to login into my test application because i get an error saying -

"Your browser is set to block cookies"

I've tried everything but i just can't seem to get the solution for this. what should i do? Please help me out here. Let me know if there is some detail missing.

RFC 2109 explicitly forbids cookie accepting from URLs with IP address

You are almost certainly accessing your test server via an IP based address.

You can try set up some kind of DNS/host file to allow you to use a fake domain name.

How to enable cookie in phantomjsdriver selenium c#?, How to enable cookie in phantomjsdriver selenium c#?. How do I driver = new PhantomJSDriver(service,phantomjsoptions); var cookieJar = driver.Manage(). How to enable cookie in phantomjsdriver selenium c#? 0 votes . 1 view. asked Jul 10, 2019 in Devops and Agile by Han Zhyang (25k points) Following is my code :

You must wait while page was loaded and then set cookie:

//Wait page loaded
cookieJar.AddCookie(new Cookie("x", "12345"));

Try this solution:

driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);//some fake url
cookieJar.AddCookie(new Cookie("x", "12345"));
driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);//cookie exsist

How to enable cookie in phantomjsdriver selenium c#?, It returns the serialized cookie data matching with the cookie name among all associated cookies. Java Python C# Ruby JavaScript. Kotlin. Login into the Application. Read the cookie information using. driver.manage ().getCookies (); Store the cookie information using FileWriter Class to write streams of characters and BufferedWriter to write the text into a file to create into a file

You can try below steps

1) Create a user profile on firefox or in chrome browser. 2) Confirm that "accept cookies" option is enabled by going to browsers settings option. 3) Load your profile via selenium.

Doing so it will ensure that enable cookie option is ON and your sessions would also get saved in the browser cache.

for chrome

System.setProperty("", "browser/chromedriverlinux");
ChromeOptions options = new ChromeOptions();
options.addArguments("--user-data-dir=/home/rohit/.config/google-chrome/Profile 1");
WebDriver driver = new ChromeDriver(options);

For Firefox

ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("ROHIT");
WebDriver driver = new FirefoxDriver(ffprofile);

To create profile in firefox try below command in terminal firefox -p

Working with cookies :: Documentation for Selenium, Why Handle Cookies in Selenium? Each cookie is associated with a name, value , domain, path, expiry, and the status of whether it is secure or  selenium-webdriver java selenium software-testing interview-questions selenium-java test-automation testng manual-testing maven eclipse cucumber jenkins page-objects career-advice api jmeter selenium-c# appium project-management python selenium-grid performance-testing testcomplete selenium-python this-vs-that soap-ui mobile-device-testing

Cookies Handling in Selenium WebDriver, As defined in WebDriver spec, Selenium WebDriver will only interact with visible How to enable cookie in phantomjsdriver selenium c#? 0 votes . selenium. It can be found within Selenium's support library WebDriver.Support.dll (under namespace "OpenQA.Selenium.Support.Events"). The source code is here and the related tests exist here. Below gives an example of how to take a screenshot when an exception is thrown while executing WebDriver tests using Selenium C# binding's EventFiringWebDriver class.

PhantomsJS rejects cookies set programmatically, Cara mengaktifkan cookie di phantomjsdriver selenium c#?. Berikut ini kode saya : case BrowserType.PhantomJS: var service = PhantomJSDriverService. Download Selenium WebDriver C# Cheat Sheet Automate The Planet Online Training Courses Increase your team knowledge on how to write automated tests for web, desktop, mobile, or API apps using WebDriver, Appium, SpecFlow, etc.

Phantomjsdriver, for general selenium architecture - How to enable cookie in phantomjsdriver selenium c#? asked Jul 10, 2019 in Devops and Agile by Han Zhyang (25k points) c#;

  • Cookies are enabled by default. There is probably another issue.
  • This has almost certainly nothing to do with any cookie settings in PhantomJS. It's either an SSL problem or a JavaScript problem. What's the site you're trying to visit and what's your PhantomJS version?
  • Its the latest version i suppose. I'm not sure if i can share the site name here...
  • @Prateek can you add the full stack trace ?
  • did you try the same with another selenium driver, .i.e. Firefox and/or Chrome? What was the result there?
  • Wow, i'm in such a luck, I have been struggeling with a non-related problem for a couple of weeks now. Our testservers' adress was IP based, and we thought it was some error in the configuration, we've literally spent days on this. I just fired up my hosts file and added a DNS to the IP. worked like a charm. Thank you!
  • PhantomJSDriver, not Chrome