Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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))                        File.Create(cookieFilePath);                   var phantomjsoptions = new PhantomJSOptions();                  driver = new PhantomJSDriver(service,phantomjsoptions);                  var cookieJar = driver.Manage().Cookies;                  driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);                  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.

like image 293
Prateek Avatar asked Aug 12 '15 16:08

Prateek


People also ask

Which method is used to access cookies selenium?

Using Selenium WebDriver API, we can query and interact with browser cookies with the help of following WebDriver's built-in methods. Get Cookies: This statement is used to return the list of all Cookies stored in web browser. manage(). getCookies();

Where we can store cookies in selenium?

When the code is executed, webdriver will store the cookie information using FileWriter Class to write streams of characters and BufferedWriter to write the text into a file named “Cookiefile. data“. The file stores cookie information – “Name, Value, Domain, Path”.


1 Answers

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.

like image 168
Aron Avatar answered Sep 23 '22 02:09

Aron