Headless Browser Testing Using PhantomJSDriver in Selenium WebDriver

Headless Browser Testing Using PhantomJSDriver In Selenium WebDriver

In the earlier post, we have seen some brief explanation on what is headless browser and in this post, we learn how to perform headless browser testing using PhantomJSDriver in Selenium WebDriver. PhantomJSDriver is one of the drivers of Selenium WebDriver. HtmlUnitDriver and PhantomJSDriver are most popular headless browsers.

PhantomJS is used for Headless Browser Testing of Web Applications that comes with in-built GhostDriver. This means that the rendered web pages are never actually displayed.


  1. Lightweight
  2. Proxy server support
  3. Fastest implementation of WebDriver
  4. Platform Independent
  5. Allows us to simulate different browsers having different versions.

You could download PhantomJSDriver executable file from here – PhantomJS Driver

Download PhantomJSDriver jar file from here – PhantomJS Jars

Usually, to run Selenium Scripts using Firefox, we initialize the Firefox driver.

Whereas while running Selenium Scripts using PhantomJSDriver you need to write the below statement

Remaining statements in your script will be as usual.

Let’s see a working example using PhantomJSDriver in Selenium WebDriver:


Different Browser Versions using PhanthomJSDriver:

We could test our scripts on different browser versions using PhanthomJSDriver. Yes, it allows us to choose our preferred browser version. See the below screenshot.

I am concluding this post about headless browser testing using PhanthomJSDriver. Check out our other post on how to perform headless browser testing using HtmlUnitDriver in Selenium WebDriver.

As always, feel free to share this post with your friends and colleagues on Facebook, Twitter, and Google Plus!

Headless Browser Testing Using PhantomJSDriver

Rajkumar SM is a founder of SoftwareTestingMaterial. He is a certified Software Test Engineer by profession and blogger & youtuber by choice. He has an extensive experience in the field of Software Testing. He writes here about Software Testing which includes both Manual and Automation Testing. He loves to be with his wife and cute little kid 'Freedom'.

2 thoughts on “Headless Browser Testing Using PhantomJSDriver in Selenium WebDriver”

  1. What is the difference between HTML unit driver and phantomjsdriver

    • Hi Prajwal, Both HtmlUnitDriver and PhanthomJSDrivr are headless browsers. HtmlUnit Driver uses Rhino JavaScript engine and PhanthomJS uses Webkit javascript engine. We could use any of these two for headless browser testing. There are some other headless browsers but these two are popular ones. HtmlUnitDriver is much faster than PhanthomJSDriver.

Leave a Comment

Share via
Copy link
Powered by Social Snap