Identifying X paths

Can anyone suggest an efficient way to capture or determine the XPath of elements on a page when working with Selenium or mabl? The elements already have a unique test identifier.

As a best practice, you must create unique data-test-ids for all UI components that you want to record as part of the flow. Applications that are created post 8.1 version of your Pega application using out-of-the-box components have the unique data-test-ids generated by default.

1 Like

As Ramesh said, unique data-test-ids are the way to identify UI components. And you created that via the Test ID in the screenshot. If you want to identify the element via XPath, you can use

//*[@data-testid=“{putyourTestIDhere}”]

So replace {putyourTestIDhere} with 201411…

If your project uses the constellation architecture, it could be that you need to add widget specific identifiers in the locator, like :combo-box:, or use the contains function of Xpath:

//*[contains(@data-testid, "{putyourTestIDhere}”)]

Additionally, if you would use Playwright for UI testing, it has a built-in locator strategy for data-testid.