简体   繁体   English

清除InternetExplorerDriver cookie硒webdriver

[英]Clear InternetExplorerDriver cookies selenium webdriver

When I create my internetExplorer instance, I use the following: 创建我的internetExplorer实例时,请使用以下内容:

public static WebDriver internetExplorerWebWDriver() {
        DesiredCapabilities returnCapabilities = DesiredCapabilities.internetExplorer();
        returnCapabilities.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);
        returnCapabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
        returnCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        returnCapabilities.setCapability("ignoreZoomSetting", true);
        return new InternetExplorerDriver(returnCapabilities);

My problem is: I have to open a secondary internetExplorer window with cleared cookie/Cache/Session and authenticate a user during the login. 我的问题是:我必须打开一个清除了cookie / cache / session的二级internetExplorer窗口,并在登录期间对用户进行身份验证。

Right now, using this code, cookie is not deleted because authentication not appears and I cannot login with different user. 现在,使用此代码,不会删除cookie,因为未出现身份验证,并且我无法使用其他用户登录。 (seems to me, the first login is saved, and used in the second window) (在我看来,第一个登录名已保存,并在第二个窗口中使用)

Any ideas? 有任何想法吗? Thanks! 谢谢!

Have you tried restarting IE after calling DeleteAllCookies each time ? 您是否尝试过在每次调用DeleteAllCookies之后重新启动IE?

Placing a driver.quit() in the after class if you using junit ? 如果使用junit,则将driver.quit()放在after类中?

I have experimented similar problems, try with the code below in @Before method: 我已经尝试过类似的问题,请尝试使用@Before方法中的以下代码:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("localStorage.clear();");      
js.executeScript("sessionStorage.clear();");
driver.manage().deleteAllCookies();

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

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