如何清除使用selenium IWebDriver缓存的IE?

时间:2016-05-27 18:39:56

标签: c# selenium

我发现了以下内容:

How to clear browser cache automatically in Selenium WebDriver?

但是,我IE_ENSURE_CLEAN_SESSION中的InternetExplorerDriver没有C#的属性。

我可以找到清除它在网络上的缓存是为了java。

C#中的等价物是什么?还需要最终做firefox和chrome ......

1 个答案:

答案 0 :(得分:2)

C#在InternetExplorerOptions.cs中有此选项:

public bool EnsureCleanSession
{
    get { return this.EnsureCleanSession; }
    set { this.EnsureCleanSession = value; }
}

所以你需要的是像

var options = new InternetExplorerOptions();
options.EnsureCleanSession = true;
// ...
IWebDriver driver = new InternetExplorerDriver(options);

如果您在评论中使用IWebDriver driver = new RemoteWebDriver(...),那么您可以

var options = new InternetExplorerOptions();
options.EnsureCleanSession = true;
DesiredCapabilities cap = (DesiredCapabilities)options.ToCapabilities();
cap.SetCapability(CapabilityType.BrowserName, DesiredCapabilities.InternetExplorer());
// continue adding other capabilities
IWebDriver driver = new RemoteWebDriver(cap)
相关问题