Web Testing - Using XPath Queries
|Top Previous Next|
When testing web applications you will often need to use XPath to query the browser DOM for elements based on the scenario under test. This section explains how you can use XPath queries with Rapise to make your browser testing more flexible and adaptive to changes on the screen.
XPath uses path expressions to select nodes in an XML document such as HTML. The node is selected by following a path or steps. The most useful path expressions are listed below:
In the table below we have listed some path expressions and the result of the expressions:
Rapise XPath Extensions
Web pages sometimes use HTML frames. The XPath works inside the frame contents. Rapise has a special syntax (that is not part of standard XPath) to combine multiple XPath statements into a single line:
The special statement:
Is used as a separator for XPath statements pointing to constituent frames.
The top-level frame is found by name 'main'
There are several different ways to use XPath queries in Rapise
Using Web Spy
To most easily use XPath queries in Rapise, we recommend using the Web Spy tool:
If you enter in the XPath query at the top, when you click Test XPath it will display all of the DOM elements that match the query:
You can now refine the query to only find the items you want to test.
When you have created the query in the Web Spy that returns the HTML elements that you were expecting, you can click on the Learn button to learn that object. What this will do is create a new Rapise object in the Object Tree that maps to this specific XPath. That means that the "object" in Rapise is effectively a pointer to this specific XPath query.
In addition to learning objects based on specific XPath, there are a set of general functions that can be used to query for objects in the web page:
Will dynamically query for any HTML element that is a child of the learned "Book Management" object that matches the XPath. In this example it will look for any table cell in a table row that has the content of the book name.