如何使用Selenium Web驱动程序和C#清除浏览器cookie [英] How to clear browser cookies using Selenium Web Driver and C#

查看:512
本文介绍了如何使用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配置文件的试用版:

  1. driver.close();

  1. 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(")进行试用:

  1. driver.get(");

  1. driver.get("");

driver.get(AppURL);

driver.get(AppURL);

希望它会对您有所帮助:)

Hope it will help you :)

这篇关于如何使用Selenium Web驱动程序和C#清除浏览器cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆