我正在使用C#通过存储的cookie运行Selenium Webdriver登录站点
im可以完美地获取cookie并存储在文本文件中,但是当我想使用此cookie时,我无法将字符串文本值转换为Selenium Cookie
My Codes:
try
{
Assert.IsTrue(driver.FindElement(By.ClassName("gravatar")).Displayed);
var session = driver.Manage().Cookies.AllCookies.ToArray();
using (StreamWriter sw = File.CreateText(textDsya))
{
foreach (Cookie cookie in session)
{
sw.WriteLine(cookie);
//sw.WriteLine(cookie.ToString());
}
}
Console.WriteLine("Stored to Text");
}
catch (Exception d)
{
Console.WriteLine(d);
}
// Reading cookies from Textfile but im getting error String cnvert to Selenium Cookie
using (StreamReader sr = File.OpenText(textDsya))
{
Cookie cukki;
string txtveri="";
while ((txtveri = sr.ReadLine()) != null)
{
//session2 = session2 + txtveri;
driver.Manage().Cookies.AddCookie(txtveri ); // Getting Error
}
}