【问题标题】:How to clear browser cookies using Selenium Web Driver and C#如何使用 Selenium Web Driver 和 C# 清除浏览器 cookie
【发布时间】:2016-04-11 00:50:14
【问题描述】:

如题,如何使用 Selenium Web Driver 和 C# 清除浏览器 cookie?

IWebDriver driver = new FirefoxDriver();
driver.Manage().Cookies.DeleteAllCookies(); //delete all cookies
System.Threading.Thread.Sleep(5000);

我尝试了上面的代码,但它没有删除会话数据。

【问题讨论】:

  • 我认为你做得很好,如果上面不起作用然后请尝试根据名称删除 cookie

标签: c# selenium-webdriver


【解决方案1】:

您可以通过以下方式清除 cookie:

driver.Manage().Cookies.DeleteAllCookies();

请记住,这只会清除当前域中的 cookie。我们与 Azure AD 上的一些网站合作。为了在测试结束时正确清除会话,我运行了 delete 方法,导航到他们的域,然后再次运行 delete 方法。

【讨论】:

    【解决方案2】:

    我认为代码是:-

    driver.manage().deleteAllCookies();
    

    不是

    driver.Manage().Cookies.DeleteAllCookies();
    

    使用相同的 firefox 配置文件试用:

    1. driver.close();

    2. driver = new FirefoxDriver(SeleniumObject.firefoxprofile); // 使用了启动前一个会话的配置文件。

    3. driver.get(AppURL);

      • 浏览器关闭。
      • cookie 丢失了。

    用 get("") 试用:

    1. driver.get("");

    2. driver.get(AppURL);

    希望对你有帮助:)

    【讨论】:

    • 在带有组织、用户名和密码的登录页面中,URL自动取了一些其他组织名称,所以想删除cookie,但似乎不起作用(断断续续)跨度>
    猜你喜欢
    • 1970-01-01
    • 2016-05-26
    • 2015-05-23
    • 1970-01-01
    • 2011-10-23
    • 1970-01-01
    • 2020-02-29
    • 2013-01-09
    • 2016-06-02
    相关资源
    最近更新 更多