ABOUT US

|

 SUPPORT

|

BLOGS

User    Pass    

 

FEATURES

|

BENEFITS

|

VIDEOS & SCREENS

|

GET STARTED

|

PRICING

 

 

 

 

 

 

You are here: Home » developers » xpath_guide

 

 

 

 

 

 

Quick Start

 

 

Addressing

LiquidTest has a range of methods for locating elements on a page. At it's simplest you can use the text on a control or link to reference it. At it's most complex you can use XPath expressions.

LiquidTest has different options when it comes to XPaths. Ideally LiquidTest tries to locate the shortest, nicest XPath for a given node. The XPath locator performs the following search:

  1. XPath
  2. Text
  3. ID
  4. Name
  5. Value

Simple: Use the text on the page

At it's simplest you can use the text on a link or button to identify it. This works well if the text on the element is unique, it doesn't work so well if you have a list of results with an edit link next to each. For example:

If your page looks like this

HTML

<a href="edit.html">Edit</a>
<input type="submit" value="Save"/>
 
<label for="foo_name">Name</label>
<input type="text" id="foo_name" value=""/>
 
<input type="radio" name="signup" value="email" id="signup_email"/>
<label for="signup_email">Contact me via e-mail</label>

then you can address elements as follows

Addresses

click("Save") // will submit the form
click("Edit") // will click the edit link
click("Name") // will put focus in text control
click("Contact me via e-mail") // will select the appropriate radio button

Pros:

  • Expressions not affected by changes in layout.
  • Tests are very readable.
  • Tests can be written based on the look of a web page, rather than a knowledge of the underlying HTML

Cons:

  • Can only be used for elements with unique text.
  • The text of labels, links and buttons may change over time, breaking any tests.

Moderate: Use the id, name or value attributes from the HTML

Alternatively if you know the HTML id of the button or link or the HTML name of a form element. For example:

HTML

<input name="widget[text]" id="widget_text" value=""/>

Addresses

click("widget[text]") // will click the text field
click("widget_text") // will click the text field

Radio buttons or check buttons can be addressed by their value.

HTML

<input type="radio" name="widget[type]" value="shonky"/>
<input type="radio" name="widget[type]" value="ultra_premium"/>

Addresses

click("ultra_premium") // will click the second radio button

Pros:

  • Can be used to address more elements than text.

Cons:

* Harder to read than the simple style.
* Less susceptible to changes in the HTML

Intense: Use XPaths

Finally you can use XPaths to address things. For example:

HTML

<html><body><a id="home_link" href="/home">My Home</a></body></html>

Addresses

click("/HTML/A") // will click the link
click("//A[1]") // will click the link
click("id('home_link')") // will click the link

Pros:

  • Can be used to address any element

Cons:

  • Can be quite complicated
  • Can be susceptible to breaking if layout changes occur. This can be mitigated against by using ids and classes to identify elements.

IFrames

Xpaths do not support traversing frames which is a common requirement on sites that use iframes or (shudder) framesets. To support this LiquidTest has a method for specifying searches inside iframes. A string in the form id('iframe1_h')–>Edit is interpreted as find the frame container at id('iframe1_h') (an iframe) then find the element with Edit inside the frame document (say a link).

When to use ids

Something about the fact that some ids are unlikely to be good test candidates if they're based on database ids or generated with layout information by web frameworks.

Controlling Recording

LiquidTest Recording and Element addressing is controlled through the LiquidTest Preferences UI.

Overview

In summary the method used to process an address on replay is:

  1. Split the address up into multiple addresses if it spans frames.
  2. For each address:
    1. Check if it is an xpath
    2. Check if it is the text of an element (say a button or link)
    3. Check if it is an id of an element
    4. Check if it is the name of a form element (say a text field)
    5. Check if it the value of a form element (say the text value of a submit button, or the value of a radio button)
  • Bookmark "Xpath guide" at del.icio.us
  • Bookmark "Xpath guide" at Digg
  • Bookmark "Xpath guide" at Furl
  • Bookmark "Xpath guide" at Reddit
  • Bookmark "Xpath guide" at Google
  • Bookmark "Xpath guide" at StumbleUpon
  • Bookmark "Xpath guide" at Newsvine
  • Bookmark "Xpath guide" at DZone


   News / Events

 

 > LiquidTest EOL Announcement - Info
 > LiquidTest Release 3.0! - Available
 > Visual Studio Plugin Released! - Release
 > Cruise Control .NET Integration - Info
 > Automate your Dev/Test Process - Webinar
 > Is manual testing crippling your project? - Blog
 > Testing complex Ajax content - Blog
 
   Recently Added Content  
 
 > Run LiquidTest's on Selenium RC/Server - Info
 > Setting up LiquidTest with Maven - Blog
 > Officially Supported Ajax Frameworks - Info
 > Atlassian Bamboo Integration - Tech
 > Setting up LiquidTest with SVN and Hudson - Blog
 > Creating Data-Driven Functional Tests - Blog
 > Reducing Test Maintenance - Blog


 © JadeLiquid, LiquidTest and WebRenderer are trademarks of JadeLiquid, all rights reserved.  Privacy Policy  |  Disclaimer

 

Dev Guide

 

 

Integrations

 

 

Updates

 

 

Contact Us