简体   繁体   English

使用IE11删除Selenium Webdriver中的cookie

[英]Delete cookies in Selenium Webdriver using IE11

I'm trying to delete all cookies before running a Selenium test. 我正在尝试在运行Selenium测试之前删除所有cookie。

According to How to clear browser cache automatically in Selenium WebDriver? 根据如何在Selenium WebDriver中自动清除浏览器缓存? and Delete cookies in Webdriver my code is: 删除Webdriver中的cookie我的代码是:

Process p = Runtime.getRuntime().exec("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255");
p.waitFor();

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION,true);
WebDriver webDriver = new InternetExplorerDriver(caps);
webDriver.manage().deleteAllCookies();

testBrowser = new TestBrowser(webDriver, "http://localhost");
testBrowser.manage().deleteAllCookies();

However, the cookies are not deleted. 但是,cookie不会被删除。

My environment is: Windows 7, 64bit, IE11. 我的环境是:Windows 7,64bit,IE11。

Any ideas? 有任何想法吗?

A simple solution for your problem is to try deleting the cookies by name. 解决问题的一个简单方法是尝试按名称删除cookie。 For example, instead of: 例如,而不是:

webDriver.manage().deleteAllCookies();

Use: 采用:

webDriver.manage().deleteCookieNamed("JSESSIONID");

I also encountered the same problem and none of the provided methods for deleting cookies worked. 我也遇到了同样的问题,没有提供删除cookie的方法。

A possible solution is that you configure your browser to launch with a clean session like this: 一种可能的解决方案是您将浏览器配置为使用如下的干净会话启动:

DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true); capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION,true);

I found the solution here: http://www.frontendtest.org/blog/ie-cache-selenium/ 我在这里找到了解决方案: http//www.frontendtest.org/blog/ie-cache-selenium/

I hope that will help. 我希望这会有所帮助。 At least, it worked for me :) 至少,它对我有用:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM