Selenium WebDriver (Java) gives the following error when running tests using a headless browser (either Firefox or Chrome) however, it runs without a problem when using a visible browser (e.g. Firefox).
org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function createHTMLDocument in object [object DOMImplementation]. (http://code.jquery.com/jquery-2.2.0.min.js#4)
There doesn't seem to be anything in the documentation about an error like this and trawling through SO hasn't turned up anything.
I'm new to Selenium WebDriver so I'm hoping it's just something obvious I've missed.
//If intialised like this it fails with the above error
webDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_38, true);
webDriver = new HtmlUnitDriver(BrowserVersion.CHROME);
//If initialised like this, it works
webDriver = new FirefoxDriver();
This is because your version of HtmlUnit misses an implementation of DOMImplementation.createHTMLDocument(). Please try with the latest version or even better with the latest snapshot.