如何使用Selenium Web驱动程序和C#清除浏览器cookie
问题描述:
与标题一样,如何使用Selenium Web Driver和C#清除浏览器cookie?
As with the title, how to clear browser cookies using Selenium Web Driver and C#?
IWebDriver driver = new FirefoxDriver();
driver.Manage().Cookies.DeleteAllCookies(); //delete all cookies
System.Threading.Thread.Sleep(5000);
我尝试了上面的代码,但没有删除会话数据.
I tried the above code but it is not deleting the session data.
答
我认为代码是:-
driver.manage().deleteAllCookies();
不是
driver.Manage().Cookies.DeleteAllCookies();
OR
具有相同Firefox配置文件的试用版:
-
driver.close();
driver.close();
driver =新的FirefoxDriver(SeleniumObject.firefoxprofile);//使用上一个会话开始时使用的配置文件.
driver = new FirefoxDriver(SeleniumObject.firefoxprofile); // Used the profile with which previous session was started.
driver.get(AppURL);
driver.get(AppURL);
- 浏览器关闭.
- cookie丢失了.
使用get(")进行试用:
-
driver.get(");
driver.get("");
driver.get(AppURL);
driver.get(AppURL);
希望它会对您有所帮助:)
Hope it will help you :)