Thursday, August 1, 2013

PhantomJS, the Headless Browser for your .NET WebDriver Tests

Did you know that Selenium already supports PhantomJS?

WebDriver is a specification for controlling the behavior of a web browser. PhantomJS is a headless WebKit scriptable with a JavaScript API. Ghost Driver is a WebDriver implementation that uses PhantomJS for its back-end. Selenium is a software testing framework for web applications. Selenium WebDriver is the successor to Selenium RC. The Selenium WebDriver NuGet Package is a .NET client for for Selenium WebDriver that includes support for PhantomJs via GhostDriver.

NuGet Packages

You need only install two NuGet packages in order to use PhantomJS with WebDriver. You will probably also want which ever Unit Testing framework you prefer. As always, I suggest xUnit.

  1. Selenium.WebDriver
  2. phantomjs.exe


After installing those, using the PhantomJSDriver is as easy as any other WebDriver!

const string PhantomDirectory =
public void GoogleTitle()
    using (IWebDriver phantomDriver = new PhantomJSDriver(PhantomDirectory))
        phantomDriver.Url = "";
        Assert.Contains("Google", phantomDriver.Title);
Shout it



  1. Replies
    1. PhantomJS is a complete browser like any other. There are several ways to post a form, the most simple being to click the submit button. :)

    2. I assume he was asking for syntax in C# for filling a form and posting it.

  2. hi tom,
    do you know how to run phantomjs.exe separately,
    i try to figure out how to make this condition :
    1. run phantomjs.exe (outside of our appication)
    2. in our application the initialization will like this :
    //no phantomjs path
    - IWebDriver phantomDriver = new PhantomJSDriver()
    // how to force the phantomDriver to use the exiting phantomjs.exe that already running on the system

    anyway iam new in phantomjs

  3. Tom, Can you point me in the right direction. When using PhantomJS and adding cookies, how does one do this via .NET

    The examples provided on the PhantomJS page are in another language. Is there a C# api or have you figured out a way to add cookies?

  4. Great, a headless web driver implementation, what I was looking for. Thanks!

  5. not getting anything how to instal PhantomJS etc


Real Time Web Analytics