froglogic / Blog / Squish/Web and XPath

Squish/Web and XPath

One of the new features of Squish/Web 3.1 (released last month) is the new XPath support. I’m blogging about that since I notice from support requests that this new feature isn’t known well enough yet by our Squish/Web customers although it solves many problems in a very elegant way.

In Squish you can retrieve a reference to an AUT object (DOM element in the web page in this case) by its name using the findObject function. In Squish/Web you can call on each such object evaluateXPath(). This will evaluate the XPath statement using the object itself as context node. You get back a XPathResult which gives you access to the result nodes or values.

So our object identification using property lists combined with XPath is really powerful. I noticed that also the other day when one of our QA engineers was working on tests for a customer in the scope of a testing kick-start where we create first tests for our customers. Here is such an example:

var item = findObject ("{tagName='TABLE' id='treeTable'}").evaluateXPath("//TR[normalize-space(TD[2])='" + itemText + "' or TD[2]/A='" + itemText + "']").snapshopItem(0);

Doing that without XPath using DOM API (firstChild, nextSibling) would be quite tedious compared to that. It’s of course also possible to do verifications this way:

var result = findObject( "DOCUMENT" ).evaluateXPath( "//*[contains(text(),'not valid with the supplied password')]" ); (result.snapshotLength, 1);

So I can only encourage Squish/Web users to make use of this new 3.1 feature as it will make life easier.

Next time I will talk about a new feature for synchronization which appeared in 3.1 which will be further improved in the upcoming 3.2.


Leave a Reply

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

Copy link
Powered by Social Snap