Web testing with Selenium and native XML/XPath

6 Nov

Not sure if Selenium RC (and also Selenium 2 / Web Driver) can find and manipulate or return a set of elements rather than a single one. I heard you can do that with Watir.

Anyhow, there’s one way alternate way to do this and is also a faster approach to working with the desired elements, particularly if you just need to read and process the values and not manipulate them.

Get the HTML page source, or better yet, innerHTML of the parent element for the elements you desire. If you get full page source, you may then need to parse out the subset of HTML you are interested in.

Then once you have that, convert to valid XML by append and prepend some root node tags, etc. to the HTML. This assumes that aside from the root node, the rest of the HTML can form valid XML, otherwise you would need further cleanup.

With the XML available, you can then pass it to XSLT processor (via code and an XSLT stylesheet) or by just traversing the XML as a DOM via XPath, returning desired nodeset to iterate over or to return specific single node or value to work with.

The XPath part is similar to using XPath for locators with Selenium. But now you can do much more with the elements in XML format to extract node names, text, and values.

The XML manipulation from native code of your language choice is likely a lot faster than having Selenium manipulate the set of elements.

One example where this is useful is parsing a table or data grid to verify content in the grid or do certain things with the content, say like fetch all values in a certain column in table which contains URL links and navigate to each of those links. This is especially useful when the grid/table is a lot of nested divs and tables via AJAX rather than a plain old basic non-nested HTML table.

Advertisements

One Response to “Web testing with Selenium and native XML/XPath”

  1. Ross Patterson January 27, 2012 at 2:46 pm #

    The Selenium RC API cannot return multiple elements in a single call. The WebDriver API can (see findElements()). But good post!

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Der Flounder

Seldom updated, occasionally insightful.

The 4T - Trail, Tram, Trolley, Train

Exploring Portland with the 4T

Midnight Musings

Thoughts on making art

Automation Guide

The More You Learn The More You Play...!

The Performance Engineer

Code.Test.Tune.Optimize.

humblesoftwaredev

Thoughts related to software development

Yi Wang's Tech Notes

A blog ported from http://cxwangyi.blogspot.com

Appium Tutorial

Technical…..Practical…..Theoretically Interesting

LinuxMeerkat

I swear! Meerkats can do Linux

PacketsDropped

Requeuing the packets dropped in my memory.

Two cents of software value

Writing. Training. Consulting.

@akumar overflow

wisdom exceeding 140 chars.

Lazy Programmer's Shortcut

Java, J2EE, Spring, OOAD, DDD & LIFE! .......all in one :)

Testing Mobile Apps

www.SoftwareTestingStudio.com

Photofocus

education and inspiration for visual storytellers

No, Seriously...

Freeing up some mind cache!

Mike Taulty

I do some developer stuff for Microsoft UK

%d bloggers like this: