0

I found the following:

How to clear browser cache automatically in Selenium WebDriver?

However, I don't have the propertity IE_ENSURE_CLEAN_SESSION for InternetExplorerDriver in C#.

All I can find to clear it's cache on the web is for java.

What is the equivalent in C#? Will also need to do firefox and chrome eventually...

Community
  • 1
  • 1
Cher
  • 2,609
  • 7
  • 32
  • 60
  • what version of Selenium are you using? [`InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION`](https://github.com/SeleniumHQ/selenium/commit/9b041165457915895883be4b8aa5566774276acc#diff-41f768943e8ae70d74aa34ec198abe9aR135) was introduced a while ago, back in version 2.35 – ddavison May 27 '16 at 18:43
  • thanks for you quick aanswer. 2.53.0 : http://www.seleniumhq.org/download/. But I'm using C#, not java. – Cher May 27 '16 at 18:47

1 Answers1

2

C# has this option in InternetExplorerOptions.cs:

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

So what you need is something like

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

If you are using IWebDriver driver = new RemoteWebDriver(...) as you said in the comments, then you can

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)
Cher
  • 2,609
  • 7
  • 32
  • 60
ohglstr
  • 10,086
  • 8
  • 41
  • 63
  • thank!! however I set my IWebDriver to a new RemoteWebDriver, can I set it? – Cher May 27 '16 at 20:42
  • do you mean `RemoteWebDriver driver = new InternetExplorerDriver(options);`? Yes, that's fine, same thing – ohglstr May 27 '16 at 21:52
  • actually I have IWebDriverdriver = new RemoteWebDriver(...) – Cher May 27 '16 at 21:53
  • Are you using capabilities to specify browser type then? – ohglstr May 27 '16 at 21:55
  • yes, DesriedCapabilities cap = DesiredCapabilities.Firefox(); I can set the option in this? – Cher May 27 '16 at 21:57
  • 1
    I added code that lets you work with `RemoteWebDriver`, BUT if you need solution for Firefox, it will be entirely different. As your question stated this is IE only – ohglstr May 27 '16 at 22:06
  • did you test it? because I get an error implying capabilities are incorrect... if not, I'll modify it, I found a way to make it work – Cher May 30 '16 at 15:18