How to Use XPath in UFT One To Identify Web-Based Objects

According to Wikipedia, XPath (XML Path Language) is a query language for selecting nodes from an XML document. Using XPath we can traverse across the path of an XML document to find a required node. Since the structure of HTML is quite similar to XML as both the files have tags and attributes, hence XPath can also be used to find a required node in an HTML file.

XPath is extensively used in open-source functional testing tools like Selenium. With the introduction of QTP11.00, HP introduced this feature to uniquely identify an object using XPath for Web-based applications. The feature is available from QTP11.00 onwards to across all UFT versions. To know more about XPath please refer to my post XPath in Selenium WebDriver with Example which is a detailed and generic tutorial on XPath that will work with any automation tool. In this article, you will learn how to use XPath in UFT.

You can also use the built-in developer tool in the Chrome browser to get the XPath of an object.

How to get XPath Using Chrome Developer Tool

Step1: Select the three dots icon at the right top corner in chrome browser>More tools>Developer tools” or Click the F12 Key.developer tab xpath

Step 2: The developer tool will be open on the right-hand side of the browser. Click on the mouse pointer icon as shown below highlighted with yellow color.

DeveloperTool-Chrome-2

Step 3: Move your mouse pointer on the object for which you want to retrieve the XPath and click on it. The HTML source code of the object will be under the Elements section of the developer tool. Right-click on the highlighted source code and select “Copy>Copy Xpath“.The absolute XPath will be copied to your clipboard. The absolute XPath could be very long. You can also install the Chrome plugin “XPath Generator” to generate the shortest relative XPath.

DeveloperTool-Chrome-098

To know more about XPath creation, Please refer to XPath With Example

When to use XPath in UFT?

The benefit of using XPath in UFT is that XPath alone is sufficient to uniquely identify an object in a Web-based application. If UFT is not able to uniquely identify an object, we can go for XPath to easily identify the object without wasting much time on smart identification and ordinal identifiers.

How to Use XPath in UFT?

There are two ways of using XPath in UFT.

Option 1: Instruct UFT to generate and store XPath value when learning Web test object by doing the setting on “Tools>GUI Testing>Advanced” and select the checkbox as shown below.

XPath in UFT
UFT will start capturing XPath of the objects and store them in the test object description as shown below. You can add the XPath property to the Test object details by clicking on the + icon and select the XPath property.
XPath-in-Obj-Repository-uft
Option 2: If the Learn and run using automatic XPath identifiers is not enabled in the “Web > Advanced node (Tools > Options > GUI Testing tab > Web > Advanced node)”, UFT might not learn the XPath property of the object and value of XPath will be showing empty.
Empty-Xpath-uft
In this scenario click on the + icon in the test object details section and add the XPath property to the test object description and manually enter the XPath in the value column.
XPath-in-Obj-Repository-uft-1
Option 3: Write the XPath in the object description using Descriptive Programming.

*Note: If you are using XPath for a Test Object in the object repository, you can disable Smart Identification and set an ordinal identifier as None as both won’t be required.

Recommended Posts

Leave a Reply