Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've heard rumors that Selenium WebDriver can run without opening a real browser window, meaning it runs in the background. I am using the C# Client Drivers, FirefoxDriver within the automated tests, and launching a class library project (containing my code) using NUnit.

  • If so, how can this be done?
  • Also, what is the benefit to doing it this way?
  • Do you still have to keep the waits (thread.sleep and implicit waits) in the code since the browser isn't open?
share|improve this question
Related:… – user246 Feb 8 '12 at 16:12
You can use headless browser for that. Such as PhantomJS, HtmlUnitDriver etc. – Ripon Al Wasim Apr 22 at 11:19
up vote 10 down vote accepted

One option is HTMLUnit which is headless but has its own proprietry JavaScript rendering engine so it is possible that it will behave differently to existing browsers (If you do use HTMLUnit don't forget to enable JavaScript when you instantiate it).

The second option is to use XVFB, this will run the tests in a virtual frame buffer environemt. This has been reported quite a few times on the Selenium users mailing list as well as the Selenium blog, see this post for some XVFB implementations:

Linking directly to the turtorials:

If you google for Selenium and XVFB you'll find lots more.

share|improve this answer
looks like some of these links broke – MacGyver Mar 11 '13 at 2:01
Main site: – MacGyver Mar 11 '13 at 2:14

It is quite easy to hide the browser without XVFB. Just install PhantomJS. Then, change this line:

driver = webdriver.Firefox()


driver = webdriver.PhantomJS()

The rest of your code won't need to be changed and no browser will open. For debugging purposes, use driver.save_screenshot('screen.png') at different steps of your code.

share|improve this answer
is it the same for Chrome tests? – someone Jan 15 at 18:20

You can attempt to run your tests inside an instance of the HtmlUnitDriver. I attempted to look at the documentation on this, but the chm file inside of the latest release seems to be botched.

There is also WebkitDriver, but that seems to be Java only for the time being.

share|improve this answer
Reminder: if you use HtmlUnitDriver, there is no guarantee the same tests will actually work in a real browser. – user246 Feb 8 '12 at 18:46
I read on the WebDriver wiki today that HTMLUnitDriver only works with the Java client drivers, so I won't be able to use this approach, since we use the C# client drivers. :-\ But I appreciate the input! – MacGyver Feb 9 '12 at 16:21

You can RUN the Test using HTMLUnitDriver, its the fastest and light weight of most of webdrivers

share|improve this answer
We use the C# drivers and NUnit, so I would have to re-write everything in Java, wouldn't I? – MacGyver Feb 9 '12 at 16:19
The syntax changes from language to language, but the Logic what you are trying to test remains the same – saikrishna Feb 13 '12 at 7:22
@MacGyver: No, you don't have to switch the language, think of HTMLUnit as the browser that is started, not as a testing framework. It does not matter for you in what language it was written, like it does not matter for firefox etc. At the very minimum you can always start the selenium server and connect to it using the webdriver bindings, specifying you want HTMLUnit. In C#: IWebDriver drive = new RemoteWebDriver(DesiredCapabilities.HtmlUnit()); There might be also a HTMLUnitDriver (for connecting directly) in the C# bindings, as C# belongs to the four officially supported languages. – zpea Jul 11 '12 at 18:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.