You are working on a project that builds a new site.
The site is coming along, page by page.
For any new page, you create some automated tests.
But sometimes, the locators used to find elements look like this:
//div[@id = 'id123']//div[contains( @class, 'class123')]/../../span[@class = 'class456']
Because of these complex locators, the automated tests are unstable.
Sometimes they work, sometimes they do not.
What can you do to improve their stability?
You may say that the test needs to be retried. Maybe the test works the second time or the third.
Or you may say that you need to use auto-healing frameworks that can identify the best locator.
Or change the test to reload the page, maybe after reloading the page, the element is found.
None of this is a good idea.
Because they are just attempts of managing the symptoms without looking at the root cause.
What is the root cause?
The html of the page is bad.
And the solution?
Ask the developers to improve it.