简体   繁体   中英

Clear InternetExplorerDriver cookies selenium webdriver

When I create my internetExplorer instance, I use the following:

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.

Right now, using this code, cookie is not deleted because authentication not appears and I cannot login with different user. (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 ?

Placing a driver.quit() in the after class if you using junit ?

I have experimented similar problems, try with the code below in @Before method:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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