There is a .delete_all_visible_cookies
method in Selenium. I was surprised to dis开发者_开发百科cover that .delete_all_cookies
in Webdriver is a part of private API thus is not accessible through @driver instance.
It is a problem for IE since it does not start a clean browser on a new test run as FF.
From what I know you have to options:
When creating the IE instance use capabilities argument:
DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true); WebDriver driver = new InternetExplorerDriver(caps);
Once initialized, you can use:
driver.manage().deleteAllCookies()
Unfortunately, I was not able to solve this issue by means of Webdriver. Finally, what I do is simply delete the cookies from the command line before running the tests. The line is
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
This part of code create an option object and sets Clean Session Property to true and passes it to Explorer driver while creating a driver instance. Works for me.
InternetExplorerOptions options = new InternetExplorerOptions();
options.EnsureCleanSession = true;
return new InternetExplorerDriver(Config.IEDriverPath, options);
IN IEDRIVER 2.53.1 The IE can delete the cache by using
capabilities.setCapability(InternetExplorerDriver.ENABLE_ELEMENT_CACHE_CLEANUP, true);
精彩评论