Creating an XPath

Introduction

Provar’s XPath Generator feature is designed to create a stable and optimized XPath for when this type of locator is needed. This is useful for mapping dynamic UI fields through the Test Builder, when standard Salesforce or Visualforce locators are not available.

This feature is especially useful for creating or modifying an XPath to make it independent of randomly changing nodes or attributes in Salesforce, such as IDs.

Creating an XPath

The example below describes how to create an XPath.

The field being mapped here is ‘Opportunity Name’, a custom Visualforce field which has a random HTML ‘ID’ assigned to it.

Although the Test Builder may accurately map this field using an ID (see Step 1), it is likely that this ID will change when running the Test Case in a different Org and so the mapped field will not be identified successfully. We will therefore use the XPath Generator to map a more stable and optimized XPath. 

Step 1: Note the ID locator being used in the current mapping. Click on the ‘By ID’ dropdown to see the other locator options.

Step 2: Choose the XPath option from the list:

Note that the XPath contains a ‘Name’ attribute which is random like an ID. This needs to be optimized.

Step 3: Click on the ‘Edit XPath’ icon as highlighted below:

Step 4: Note the tags which have appeared under the locator field, e.g. HTML, DIV, INPUT. Colors are used on the tags to identify those which are currently being used in the XPath.

In this case, the ‘INPUT’ tag is being used along with the ‘Name’ attribute.

A green tag indicates that you have selected this tag for editing and attribute selection.

Other colors will also appear to indicate the following:

  • Grey: Tag is not being used in the current XPath
  • Pink: Tag is being used in the current XPath
  • Blue: This is the last or the focussed tag of the XPath

Step 5: Uncheck the ‘Name’ attribute and note the change in XPath. Note also that multiple fields are now highlighted in the browser, indicating that our XPath is not yet optimized:

Step 6: Now click on the ‘DIV’ tag, going one step up the hierarchy in the HTML. Note that the ‘DIV’ tag is now highlighted in green. The focus has also narrowed to highlighting fewer fields.


Step 7: Check the ‘Class’ attribute. Note that the XPath now includes the Class name and only ‘Opportunity Name’ is highlighted. This indicates that our XPath is now optimized as well as stable, being independent of Field ID and Name.

Finally, click the ‘Close XPath Edit’ icon as highlighted below:

Step 8: Confirm the XPath to map this field by clicking ‘Add & Do’.

Notes

Note that you can reset to the default XPath at any time during XPath creation by clicking the ‘Reset XPath’ icon as highlighted below:

2017-05-12T11:34:48+00:00

Leave A Comment