Click here to monitor SSC
  • Av rating:
  • Total votes: 194
  • Total comments: 6
Michael Sorens

XPath, CSS, DOM and Selenium: The Rosetta Stone

04 April 2011

Some programming conventions are best represented in a chart. Nobody will claim that XPath or CSS are entirely intuitive, as they are terse, economical ways of identifying elements in a hierarchy. However, a chart with recipes and examples is a different matter. Suddenly, apps like Selenium IDE are made easier.

A little learning is a dangerous thing." [Alexander Pope, An Essay on Criticism]

Have you absorbed some knowledge of XPath or CSS or DOM, and tried to put it to use, and then realized that you do not know all the right incantations? Curiously, these three technologies are all designed to do similar things in selecting elements within markup, so it is possible to illustrate how you express the same target in each technology. The (XPath | CSS | DOM | Selenium) Rosetta Stone and Cookbook brings you all the recipes you need to be productive in each technology, and helps you to transfer your knowledge between them.

XPath, CSS, and DOM are a fairly diverse set of technologies yet they have quite a bit in common. Each provides powerful syntactic structure to select elements, XPath operating on general XML (including well-formed HTML), while CSS and DOM operate strictly on HTML. The wallchart shows you the proper syntax to specify selection locators in each of the three technologies. And because of their parallel nature, the wallchart is also organized as a cross-reference so you can leverage what you know in one of these technology towards another.

Finally, the wallchart cuts a swath across these three primary technologies to provide a Selenium perspective, showing you the idiosyncrasies of each that you need to know to apply those technologies with the Selenium web testing platform. Exceptions to the standard rules are highlighted and special Selenium syntaxes are provided. All the recipes, except those specifically noted, may be tested directly in Selenium IDE to see how they work. A validation test suite provided for the wallchart itself is a great place to start your experimentation!

Because your preferred format for a reference could differ from the next person's, you have two versions of the wallchart available here for download; they differ dramatically in style but are identical in content.

No. I can't read it either. The actual wallchart can be downloaded from the speech-bubble at the head of the article.

For the same information but arranged by groups.

Michael Sorens

Author profile:

Michael Sorens is passionate about software to be more productive, evidenced by his open source libraries in several languages (see his API bookshelf) as well as SqlDiffFramework (a DB comparison tool for heterogeneous systems including SQL Server, Oracle, and MySql). With degrees in computer science and engineering he has worked the gamut of companies from Fortune 500 firms to Silicon Valley startups over the last 25 years or so. Current passions include PowerShell, .NET, SQL, and XML technologies (see his full brand page). Spreading the seeds of good design wherever possible, he enjoys sharing knowledge via writing (see his full list of articles), teaching, and StackOverflow. Like what you have read? Connect with Michael on LinkedIn and Google +

Search for other articles by Michael Sorens

Rate this article:   Avg rating: from a total of 194 votes.


Poor

OK

Good

Great

Must read
Have Your Say
Do you have an opinion on this article? Then add your comment below:
You must be logged in to post to this forum

Click here to log in.


Subject: Missing download links
Posted by: Anonymous (not signed in)
Posted on: Monday, April 18, 2011 at 2:12 AM
Message: The links to download the wallcharts are missing.

Subject: Download links
Posted by: dirq (not signed in)
Posted on: Monday, April 18, 2011 at 6:57 AM
Message: He says the links are at the bottom of the page, but in fact, they're at the top next to the article title.

Subject: Quote from the article
Posted by: Phil Factor (view profile)
Posted on: Monday, April 18, 2011 at 7:05 AM
Message: 'The actual wallchart can be downloaded from the speech-bubble at the head of the article' (quote from Michael's article).
I referred to this wallchart in my article 'How to Import Data from HTML pages' http://bit.ly/ek86Vg Without the wallchart, I wouldn't have been able to finish the article!

Subject: thanks!
Posted by: Anonymous (not signed in)
Posted on: Monday, April 18, 2011 at 10:32 AM
Message: Michael,

I love it, thanks!

Peter

Subject: download is easy
Posted by: Anonymous (not signed in)
Posted on: Monday, April 18, 2011 at 10:34 AM
Message: just a click on the wallchart starts download too.
p.

Subject: thanks and please update css no longer supports contains
Posted by: BugMeNot (view profile)
Posted on: Thursday, January 22, 2015 at 4:34 PM
Message: selenium no longer supports css contains.
see:
https://code.google.com/p/selenium/issues/detail?id=987

 

Top Rated

Rethinking the Practicalities of Recursion
 We all love recursion right up to the point of actually using it in production code. Why? Recursion... Read more...

Acceptance Testing with FitNesse: Multiplicities and Comparisons
 FitNesse is one of the most popular tools for unit testing since it is designed with a Wiki-style... Read more...

Acceptance Testing with FitNesse: Documentation and Infrastructure
 FitNesse is a popular general-purpose wiki-based framework for writing acceptance tests for software... Read more...

Prototyping Desktop Deblector
 Deblector is an open-source debugging add-in for .NET Reflector; the Reflector team investigated... Read more...

.NET Reflector Through the Looking Glass: The Pudding
 There a number of ways in which Reflector, either by itself or with an Addin, allows you to analyse... Read more...

Most Viewed

A Complete URL Rewriting Solution for ASP.NET 2.0
 Ever wondered whether it's possible to create neater URLS, free of bulky Query String parameters?... Read more...

Visual Studio Setup - projects and custom actions
 This article describes the kinds of custom actions that can be used in your Visual Studio setup project. Read more...

.NET Application Architecture: the Data Access Layer
 Find out how to design a robust data access layer for your .NET applications. Read more...

Calling Cross Domain Web Services in AJAX
 The latest craze for mashups involves making cross-domain calls to Web Services from APIs made publicly... Read more...

Build and Deploy a .NET COM Assembly
 Phil Wilson demonstrates how to build and deploy a .NET COM assembly using best practices, and how to... Read more...

Why Join

Over 400,000 Microsoft professionals subscribe to the Simple-Talk technical journal. Join today, it's fast, simple, free and secure.