QTP What is XPath? XML and XMEN

QTP/UFT Published on:
UFT UPdate

“Mutation: it is the key to our evolution. It has enabled us to evolve from a single-celled organism into the dominant species on the planet. This process is slow, and normally taking thousands and thousands of years. But every few hundred millennia, evolution leaps forward. Prof.” – Charles Francis Xavier
XPath allows you to find different parts of XML documents. This is powerful, because it enables you to write expressions that return specific info in an XML document. Using VBScript in QTP or UFT will unleash this new power for you.

Xpath and Trees

The classic method for visualizing an XML document is to imagine an upside down tree. The trunk is considers the ROOT, and the branches are nodes. Location paths are a way to select the node(s) that you’re interested in. To try these examples download the xmen.xml

1. The Simplest Location Path

To return all the text values found in the XML’s nodes you can use a Root location path, which is a forward slash (/). For example, to return all the values in our XMEN XML we would use:


Should return all text values in the XML file

2. The Second Easiest Path – Child Elements

The Child element location allows you to obtain a single element name. It will select all child elements that match the name specified. So, to return the first person’s ‘name’ element value in our XMEN doc we would use:

To return the first XMEN name value match:

Result: Should return the name ‘Professor X'

3. To return the all the XMEN name values


Should return all the XMEN names

4. Elements Attributes

You can also return a particular attribute of an element using the @ sign.

To return all the ‘power’ elements text values that have ability type equal to two:


Should return all the power value “Superhuman senses.”

5. To return the attribute text value of an element:


Should return the type attribute value of 1


This should be enough to get you started.  Congratulations!! You are now an official XMEN XPath QTP Mutant.

Fellow Bibliomaniacs
For everything you ever wanted to know about XPath check out:

5 responses to “QTP What is XPath? XML and XMEN”

  1. Let me explain what my problem is

    1 Page A has 4 links aa,bb,cc,dd
    1.1 Click aa link to go to popup that has inboxes ggg,hhh

    2 Page B has 4 links aa,bb,cc,dd
    2.1 Click aa link to go to popup that has inboxes ggg,hhh

    NOW, ggg,hhh inboxes have same property values whether i go to aa of page A or aa of page B. When i run the test, test stops at ggg of page A and doesn’t enter value and throws error, “Several objects have same property values.Use unique value to identify the object”

    How to make tool recognize objects uniquely?
    Should RTO values be changed and made unique?
    How do you manage with a website that has several unique fields?

    • Nand » First i usually would try to use an index value EX WinObject(“text:=ggg”,”index:=1″) . Or try to find a combination of properties that would make the objects id unique. If there is a label next to the field you could also try QTP’s visual relation identifier. Are you using an OR or descriptive programming?

  2. i m trying to use the 2nd method you have given.
    2. The Second Easiest Path – Child Elements

    While using i m getting an error as Object required on the line number where i m trying to print the value. please help how to resolve this issue???

  3. Hi joe,
    I have a requirement to search for the tag value and get the value.
    here it is ..





    How can search for test3 and get the value of memberof? Please guide me here with your suggestions.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

UFT UPdate