5 Reasons I Chose Selenium over PhantomJS

Screen Shot 2013-08-21 at 2.43.59 AM

Selenium vs PhantomJS, CasperJS, or ZombieJS do almost the same thing, automate browsers, but why should you use one over the other? It turns out that there are some use cases when using Selenium might give you advantages over a headless toolkit.

I’m not saying that I always use Selenium. I prefer to use PhantomJS because it would have less overhead and performs better. However, because of specific edge cases I needed to use a real browser where the headless toolkit just didn’t cut it.

(This is a follow up post to Running Headless Selenium with Chrome.)

#1. Easier development with Inspect Element

While writing automation against other pages, I didn’t always know what HTML element I needed to write code for. So I would write code by using a UI, right clicking on some part of the page, then selecting the HTML element I wanted.

#2. When you need a specific JavaScript engine

PhantomJS uses QtWebKit. That means PhantomJS is not the same JavaScript engine that Chrome uses. (source) For the most part it won’t matter. However, if you need to be 100% sure it looks and acts like a browser then you need a real browser.

#3. When the website uses strange browser detection

An exmaple use case is scraping websites. I’ve found websites that give you slightly different HTML than they present a browser even after you change the user-agent string. My guess is they also might attempt to detect HTML5 features or a Flash plugin.

From an SEO perspective the change in HTML it’s nothing that I would consider a negative or a cloak but the interesting bits I wanted weren’t there to scrape or interact with. A real browser was the only thing that worked for me.

#4. I actually need Flash

One of our features uses ZeroClipboard. It works partly by using an invisible Flash movie. So by default, I will need a real browser to make this test work.

#5. When you need a browser specific features

I have not used Selenium this way yet but I will need it soon. Some features I work on include steps that uploads files, print from the webpage, opens separate windows, switches tabs, and uses browser plugins.

Some features I work on right now include these steps. While we have those features covered in unit tests, I’m also testing them manually for important features. I anticipate this is a good way to automate those tests.


Again, I’m not saying that I always use Selenium. I only use it for specific use cases because it’s the only thing that will work.

6 thoughts on “5 Reasons I Chose Selenium over PhantomJS

  1. Selenium is a fantastic tool for crawling webpage content. Its really welll supported within a significant amount of programming languages (PHP, Perl, Python, Java) and the project itself very well maintained. Great article, Chris!

  2. Robert Fletcher

    Another use case that is an issue for a project I’m working on is that you need drag and drop. Headless drivers have some basic functionality, but if you need to be able to set precise coordinates you’re stuck with Selenium.

  3. Small typo : An exmaple.

    Otherwise, very interesting article.

  4. JSON wire protocol is juste too much of an abstraction on top of what browsers actually do, strong point of headless browsers is that it’s really possible to fully control what’s going on

  5. You have really helped me to clarify issues with the #2 & #3 that you pointed out. My problems is that the Java part of it doesn’t cut it for me. How do I go about learning this Selenium, I intend to work from Python with it. Please help, thanks.

    And thanks for this post.

  6. I have also found Selenium to be very useful for me like you mentioned in #3.
    Disqus.com will not PhantomJS to pass through

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>