Curious how QA engineers are handling locator stability issues in modern automation frameworks today.

I’m exploring how QA engineers are currently dealing with locator stability challenges in modern web automation — especially with Shadow DOM, dynamic elements, and iframe-heavy applications. Curious what strategies, tools, or practices are working best today.

Hey, are you automating a Salesforce application, by any chance? What you describe sounds familiar to that context. It’s true that stable locators can be an issue in this world, but since I completely rewrote our UI automation about one year ago, we’ve only had one instance of locator instability, due to something Salesforce changed. So, although there are challenges, there are definitely also solutions.

Here’s a snippet from our readme, specifically on the topic of locators:

### Locators

There are different types of locators which can be used to specify UI elements.  Keeping the above in mind, locators should be used in the following order:

1. Test IDs
    ```
    page.getByTestId('save-button')
    page.locator('[data-testid="modal-close"]')
    ```
    Note: These are very rarely provided by Salesforce, so can be all but ignored
2. CSS selectors
    ```
    page.locator('button[name="Account.NewOpportunity"]')
    page.locator('input[name="StartDateFirstBillingPeriodRequired"]')
    ```
3. Text selectors
    ```
    page.getByRole('button', { name: 'Speichern' })
    page.locator('button:has-text("Weiter")')
    ```
4. XPath selectors
    ```
    page.locator('//button[@name="Account.NewOpportunity"]')
    ```
    Note: These are not best practice, and should only be used as a last resort

**Any attribute which appears to include a random combination of characters should not be used!!**
```
page.locator('[lwc-2qpe2t0sbck]')

I hope that helps. I’m curious to know about your own experiences / solutions in this area.

1 Like

Thanks for sharing its really helpful. I agree that having a clear locator priority strategy makes a big difference.

I actually started building a small tool (Q-ARK) to analyze and rank locator stability because i kept seeing teams struggle with dynamic attributes and framework updates. The idea is to evaluate multiple locator options instead of relying on the first generated one.

Still experimenting with it, but its been interesting to see how much instability comes from structural dependencies.

1 Like