Creating an XPath
Provar’s XPath Editor 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.
Note that Provar has introduced a new XPath Editor in version 1.9.7 to make it easier to generate a reliable XPath for any field. This editor replaces Provar’s earlier XPath Editor. Steps for using the new XPath Editor are below. If you are on a Provar version earlier than 1.9.7, refer to the section at the bottom of this page, Creating an XPath (1.9.6 and earlier).
Creating an XPath (1.9.7+)
Provar has introduced a new XPath Editor in Provar version 1.9.7 to make it easier to generate a reliable XPath for any field. This editor helps create an optimized XPath by autopopulating options for the user, offering alternatives where available and giving instantaneous feedback in the browser window.
This editor is available in the Test Builder whenever a field is being mapped and an XPath option is available.
Opening the XPath Editor
Start by mapping the field as normal. The Test Builder will present a draft test step with the Field Locator section set to the default option, which is By SLDS Locator in the example below:
Click into the By SLDS Label and change it to By XPath. This will open the XPath editor:
Note that the element the XPath matches is highlighted in the browser in red.
Using the XPath Editor
Within the XPath editor itself, there is a list of qualifier attributes that correspond to the available entry:
These qualifier attributes contain all the attributes for the node that the cursor is focused on:
We can add more attributes to the populated Xpath from the Add another dropdown in the editor, as below:
Once selected, the attribute will appear in the editor’s list of attributes so that a value can be set.
In general, these XPath locators will follow a sequence of ID, Name, Text, Label. This means that, if a field has these attributes present in the HTML structure, the locators will always show in this order.
For example:
In addition, for any field that has a label available in the HTML structure, a label locator will always be shown as an alternative locator:
Provar also provides an autocomplete option for the XPath by providing a list of available child nodes to the node that the focus is currently on. Pressing Ctrl + Spacebar will open the autocomplete list:
If the cursor focus is after ‘/’ and in front of a tag name, using autocomplete will replace the tag name with the newly chosen option.
Provar also supports the use of grouping and unions within the XPath:
Please note that the XPath used post-Union character will not reflect its qualifier attributes.
Troubleshooting XPaths
If the XPath doesn’t match any elements, an error is shown, as below. The qualifiers remain editable so that the XPath can be updated to match an element.
If the XPath is invalid, an invalid error will be shown and the qualifier attributes will be hidden from editing until the XPath is fixed:
In some cases the XPath editor will present a warning, for example if the XPath matches more than one element on the page. In this case the warning is shown in the editor but the step can still be added to the test if wanted.
In some cases a Failed to parse XPath warning may appear. If this happens the qualifier attributes are hidden until the issue is resolved. If you are not sure how to resolve the issue, file a case via the support portal.
Creating an XPath (1.9.6 and earlier)
Note that Provar has introduced a new XPath Editor in version 1.9.7 to make it easier to generate a reliable XPath for any field. This editor replaces Provar’s earlier XPath Editor. However, if you are on a Provar version earlier than 1.9.7, the instructions below describe how to use this editor.
In addition, if you should need to switch back to the old XPath editor for any reason, this can be done by making the following entry in the provar.ini file:
-Dcom.provar.chrome.ide.showEnhancedXpathEditor=false
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.
- General information
- Licensing Provar
- Provar trial guide and extensions
- Using Provar
- API testing
- Behavior-driven development
- Creating and importing projects
- Creating test cases
- Custom table mapping
- Functions
- Debugging tests
- Defining a namespace prefix on a connection
- Defining proxy settings
- Environment management
- Exporting test cases into a PDF
- Exporting test projects
- Override auto-retry for Test Step
- Managing test steps
- Namespace org testing
- Provar desktop
- Provar Test Builder
- Refresh and Recompile
- Reload Org Cache
- Reporting
- Running tests
- Searching Provar with find usages
- Secrets management and encryption
- Setup and teardown test cases
- Tags and Service Level Agreements (SLAs)
- Test cycles
- Test plans
- Testing browser options
- Tooltip testing
- Using the Test Palette
- Using custom APIs
- Callable tests
- Data-driven testing
- Page objects
- Block locator strategies
- Introduction to XPaths
- Creating an XPath
- JavaScript locator support
- Label locator strategies
- Maintaining page objects
- Mapping non-Salesforce fields
- Page object operations
- ProvarX™
- Refresh and reselect field locators in Test Builder
- Using Java method annotations for custom objects
- Applications testing
- DevOps
- Introduction to test scheduling
- Apache Ant
- Configuration for Sending Emails via the Provar Command Line Interface
- Continuous integration
- AutoRABIT Salesforce DevOps in Provar Test
- Azure DevOps
- Running a Provar CI Task in Azure DevOps Pipelines
- Configuring the Provar secrets password in Microsoft Azure Pipelines
- Parallel Execution in Microsoft Azure Pipelines Using Multiple build.xml Files
- Parallel Execution in Microsoft Azure Pipelines using Targets
- Parallel execution in Microsoft Azure Pipelines using Test Plans
- Bitbucket Pipelines
- CircleCI
- Copado
- Docker
- Flosum
- Gearset DevOps CI/CD
- GitHub Actions
- Integrating GitHub Actions CI to Run Provar CI Task
- Remote Trigger in GitHub Actions
- Parameterization using Environment Variables in GitHub Actions
- Parallel Execution in GitHub Actions using Multiple build.xml Files
- Parallel Execution in GitHub Actions using Targets
- Parallel Execution in GitHub Actions using Test Plan
- Parallel Execution in GitHub Actions using Job Matrix
- GitLab Continuous Integration
- Travis CI
- Jenkins
- Execution Environment Security Configuration
- Provar Jenkins Plugin
- Parallel Execution
- Running Provar on Linux
- Reporting
- Salesforce DX
- Git
- Team foundation server
- Version control
- Salesforce testing
- Adding a Salesforce connection
- Assert Page Error Messages on Add/Edit Product
- Dynamic Forms
- Internationalization support
- List and table testing
- Salesforce Release Updates
- Salesforce Lightning Testing
- Salesforce Lightning Web Component (LWC) locator support
- Salesforce console testing
- Visualforce Testing
- Performance Best Practices
- Testing best practices
- Troubleshooting
- Browsers
- Configurations and permissions
- Connections
- DevOps
- Error messages
- Administrator has blocked access to client
- JavascriptException: Javascript error
- macOS Big Sur Upgrade
- Resolving failed to create ChromeDriver error
- Resolving Jenkins license missing error
- Resolving metadata timeout errors
- Test execution fails – Firefox not installed
- Update to Opportunity field validation behaviour
- Licensing, installation and firewalls
- Memory
- Test Builder and test cases
- Release notes