I want to:
- Login to a website
- Save Cookies
- Give user a choice to do A, B or C
- A,B and C all require being logged in.
- Each will open a FirefoxDriver and do their own thing
What i want to do, is login ONCE, save the cookies from that, and add them to any other FirefoxDriver i want to open.
Right now I'm trying to save the cookies in
public ReadOnlyCollection<Cookie> Cookies { get; set; }
which is the result of
WebDriver.Manage().Cookies.AllCookies;
Assuming login worked and cookies were saving in the above, I have this:
WebDriver = new FirefoxDriver();
WebDriver.Navigate().GoToUrl("http://www.example.com");
if (cookies != null)
{
var s = WebDriver.Manage().Cookies; //Logged out cookies
WebDriver.Manage().Cookies.DeleteAllCookies(); //Delete all of them
var sd = WebDriver.Manage().Cookies; //Make sure theyre deleted
foreach (var cookie in cookies)
{
WebDriver.Manage().Cookies.AddCookie(cookie);
}
var ss = WebDriver.Manage().Cookies;
WebDriver.Navigate().GoToUrl("http://example.com/requiresloginpage");
}
The problem is, howevering over "ss" in this case, gives this exception error
AllCookies = 'ss.AllCookies' threw an exception of type
'OpenQA.Selenium.WebDriverException'
base {System.Exception} = {"Unexpected problem getting cookies"}
InnerException = {"Cookie name cannot be null or empty string\r\nParameter name: name"}
I'm passing 8 cookies (total number when youre logged in) - and all of them seem set and ok. Not sure what I'm doing wrong