I am running Selenium along with cucumber with java, and trying to Capture screenshot on fail with htmlunitdriver in java?

Can you help me how to capture a screenshot with HTMLunitDriver. I tried phantomjs but unfortunately phantom has no function like browserVersion in HtmlUnitDrive. that is why we have to stay with HTMLUNITDRIVER.

1 Answer 1


HtmlUnit does not have screenshot function, as the page is not rendered.

Here is the feedback from the developers on a similar question:

HtmlUnit is a headless browser, and makes no attempt to render content. This is the reason that the HtmlUnitDriver does not support the TakesScreenshot interface.

If you need to take screenshots, then I'd suggest using something like the FirefoxDriver.

Marking as "WontFix" as this is the expected behaviour.


The thread notes that someone made some code to throw all the html,css,images etc into a zip for analyses or manual rendering in a real browser. Have a look at this HtmlUnit extentions here: https://groups.google.com/forum/#!msg/selenium-developers/PTR_j4xLVRM/k2yVq01Fa7oJ

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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