Extending Selenium

I think Selenium is great for acceptance testing websites. But I’ve found it can be pretty slow to do certain things in Internet Explorer, in particular anything to do with xpath queries.

Something we need to test in work is that a particular CSS class is set on a particular element. Currently Selenium doesn’t provide a way to do this without using an XPath query. However, it is fairly easy to extend Selenium and implement this without the use of XPath. The basic idea is to use Selenium’s getEval method within an extended DefaultSelenium and wrap a particular call inside a standard Java method.

Here’s an example of what I’m waffling on about:

public class ExtendedSelenium extends DefaultSelenium {
  public String getCssClass(String elementId) {
    return getEval("{selenium.browerbot.findElement('" + elementId + "').className;}")

Selenium provides the browserbot object, this has many handy methods that work cross browser. They tend to be pretty efficient too. However you’ll have to be careful that any extensions you write, are either only going to be run on a single browser, or you write cross browser code.

Have fun!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: