First look at Selenium Inspector

Last week, Team Dev released Selenium Inspector – a Java API wrapper over the existing Selenium Java API. Note that Selenium Inspector API does not replace the Selenium Java API, you can use both at the same time! This article compares the same program written in 3 different ways: Selenese (HTML) using Selenium IDE, in Java using Selenium Java API and in Java using Selenium Inspector API.

The Test

The test goes to and searches for the keyword “yahoo”. It then makes sure that the link “Yahoo!” appears in the search results.

Approach 1: Using Selenium IDE

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="en" lang="en">
<head profile="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<table cellpadding="1" cellspacing="1" border="1">
            <td rowspan="1" colspan="3">helloworld</td>

Approach 2: Using Selenium API

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;

public class HelloWorldSeleniumTestCase {
    private static DefaultSelenium selenium;
    private static SeleniumServer seleniumServer;

    public static void setUp() throws Exception {
        seleniumServer = new SeleniumServer();

        selenium = new DefaultSelenium("localhost", 4444, "*firefox", "");

    public void testHelloWorld() {"");

        selenium.type("q", "yahoo");"btnG");


        // assert that the search box remembers the query
        Assert.assertEquals("yahoo", selenium.getValue("q"));

        // assert that you find the expected link in results

    public static void tearDown() {

Approach 3: Using Selenium Inspector API

You need junit 4.5 to run. If you are using Junit 4.3 or lower, you will get the following error.

Caused by: java.lang.ClassNotFoundException: org.junit.runners.BlockJUnit4ClassRunner
	at Method)
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	at java.lang.ClassLoader.loadClassInternal(

JUnit code

import org.junit.BeforeClass;
import org.junit.Test;
import org.seleniuminspector.ElementByLocatorInspector;
import org.seleniuminspector.ElementInspector;
import org.seleniuminspector.SeleniumFactory;
import org.seleniuminspector.SeleniumHolder;
import org.seleniuminspector.SeleniumTestCase;
import org.seleniuminspector.SeleniumWithServerAutostartFactory;
import org.seleniuminspector.ServerLoadingMode;
import org.seleniuminspector.html.InputInspector;

public class HelloWorldSeleniumInspectorTestCase extends SeleniumTestCase {
    public static void initSeleniumFactory() {
        SeleniumHolder seleniumHolder = SeleniumHolder.getInstance();
        SeleniumFactory factory = new SeleniumWithServerAutostartFactory(4444, "*firefox", "");

    public void submitData() {

        InputInspector inputField = new InputInspector("q");



        // assert that the search box remembers the query

        // assert that you find the expected link in results
        ElementInspector elementInspector = new ElementByLocatorInspector("link=Yahoo!");


Selenium API is action oriented, various actions that you can perform with the selenium API. There is a roughly one to one mapping of Selenium IDE commands and Selenium Java API. However, Selenium Inspector is based around objects called “Inspectors”. Inspectors are objects that inspect a specific things of the page, e.g. InputInspector which inspects an input field. Inspector then provide you with easy high level api. For example Input Inspector provides the following high level commands:

Class InputInspector

d assertValue(java.lang.String value) – Assert that the input has the given value
boolean disabled() – Assert that the input is disabled
java.lang.String name() – Get the name of the input
java.lang.String type() – Get the type of the input
void type(java.lang.String text) – Type of given text in the input
void typeKeys(java.lang.String text) – Type the given keys in the input
java.lang.String value() - Get the value of the input

The idea is to provide easy to functions in addition to the existing Selenium Java API.

Some of the other inspectors are:

  • ElementInspector – This is the base class for most of the other Inspectors. The purpose of ElementInspector is to provide easy means for inspecting client-side DOM elements in Selenium functional tests. An instance of ElementInspector is bound to a specific DOM node that is specified during the element’s creation.
  • ElementByExpressionInspector – Defines an inspector for an element retrieved with an associated script. Note that like for Selenium.getEval method, the script runs in context of “selenium” object. Use “window” to refer to the tested window.
  • ElementByLocatorInspector – Inspects an element by the specified Selenium locator.
  • ElementByReferenceInspector – Inspects the same element as the associated element inspector. This class is mainly useful for extending by other specialized inspectors to provide a flexible way of referring to other elements. Some of the available extensions are InputInspector, LiInspector, TableInspector, TableRowInspector, TableSectionInspector, TextAreaInspector, UlInspector
  • Other inspectors – DocumentInspector, TableCellInspector, TableColumnInspector, SubElementByPathInspector, SubElementByExpressionInspector, WindowInspector
  • JSF inspectors – the Selenium Inspector websites talked about OpenFaces Inspectors — a package of selenium inspectors created for easier testing of OpenFaces JSF components. I haven’t taken a look at it but I think the idea is to encapsulate and reuse JSF input specific behavior in a [Inspector] class and reuse!


Inspectors try to provide high level functionality to various elements in the page to provide ease of use and facilitate code reuse!


Official Selenium Inspector website

Related posts:

  1. Maven Selenium
  2. The plugin ‘org.codehaus.mojo:selenium-maven-plugin’ does not exist or no valid version could be found
  3. 2 ways to convert Java Map to String
  4. Java 7: New Feature – automatically close Files and resources in try-catch-finally
  5. Tweet your builds with Maven Twitter Plugin

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Adobe Flash playerPlugin by wordpress themes