Selenium Webdriver我如何使用C#将字符串Cookie转换为Cookie Cookie

时间:2019-11-20 16:15:54

标签: c# selenium-webdriver cookies selenium-chromedriver

我正在使用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
                        }
                    }

0 个答案:

没有答案