So far i browsed the same topic over the internet but not getting the right answer.

I want to execute the script/suite with HTMLUnit driver but it getting fail and showing exception:

Exception while taking screenshot org.openqa.selenium.htmlunit.HtmlUnitDriver cannot be cast to org.openqa.selenium.TakesScreenshot

As I understood it got stuck at Screenshot capturing code. So my question is . Is there any way to capture screenshot while executing script using HTMLUnit driver ?

Because in My framework i'm calling the common takeScreenshot method from so many places wherever any change happening on the page like:

before filling the form --> after filling the form --> after submit the form

So i can't remove all those method call from whole suite.

1 Answer 1


The closest thing I've found is this extended HTMLUnitDriver. For more context, see also this SO question.

Following the comments on that question, why not use PhantomJS, which apparently supports screenshots?

  • you are right, I have tried with PhantomJS driver, it's working fine but my concern is about htmlUnit
    – NarendraR
    Commented Aug 2, 2017 at 14:46
  • PhantomJS is no longer developed.
    – dzieciou
    Commented Oct 1, 2017 at 19:05

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.