user880954
user880954

Reputation: 7687

Selenium - How do I hide the browser

When I used WATIN I am able to hide the browser and my tests are a lot quicker. Now I am looking to do the same with selenium in c# if possible.

Upvotes: 3

Views: 5283

Answers (2)

nilesh
nilesh

Reputation: 14307

As @Guillaume answered, your choice is to use HtmlUnitDriver. However I would like to add that HtmlUnitDriver can simulate real browsers too, here is how you could do that in Java. I am not too familiar with c# bindings. I am sure there must be something similar.

HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);

Or you could use the capabilities like below,

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setBrowserName("firefox");
capabilities.setVersion("3.6");
capabilities.setJavascriptEnabled(true);
HtmlUnitDriver driver = new HtmlUnitDriver(capabilities);

Note that this is not recommended, from the wiki page "You should not really be doing this, as web-applications are better coded to be neutral of which reasonably recent browser you are using."

Upvotes: 1

Guillaume
Guillaume

Reputation: 22822

I don't know about C# unfortunately, but when using Selenium in Java for my web tests, I use it with HtmlUnit, which is a GUI-less browser made specially for that. They may have a version for C# or not, I'm not sure.

I've found similar questions on SO though. I haven't read the answers, but you can:

C# library similar to HtmlUnit

.net equivalent of htmlunit?

Html Parser & Object Model for .net/C#

Upvotes: 4

Related Questions