Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.7k points)

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.

1 Answer

0 votes
by (62.9k points)

You must wait until the page gets loaded and then set the cookie: 

driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);

//Wait page loaded

cookieJar.AddCookie(new Cookie("x", "2468"));

driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);//some url

Hope this helps!

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...