Best way to Locate Element


I am new to Testing automation but managing testing team who does automation. most of automation are Sales force based application

We have found that sometimes, the IDs or xpath of element (which we have used as locator) gets changed and because of that the scripts fails

what is permanent solution to handle these type of failures?

How can we ensure the scripts does not fails when ID or xpath gets changed?

Please guide me as the xpath and ID changes are creating major problem for us and we are not getting value of automation as the scripts used to fail because of ID or Xpath changes?

Thanks with Regards

Short answer: there is no permanent solution. :persevere:

Improved answer: get better locators. :smile:

I presume when you say ID’s are changing, that means that ID’s are generated dynamically. In that case, I suggest trying parametrization. I believe the following articles and discussions could be helpful:


thanks for your response

Yes, we have observed, ID is getting generated dynamically so we started using xpath and thought xpath is unique and will not change but it also changes sometime…so there is not guarantee that the test scripts will not fail. it will fail if the xpath gets changed

could you please elaborate more on this below? Parameterization is not available with which selection method? if it is not available then xpath is the only locators to use or we can use any others locators which are reliable

Warning Parameterizing Web/Mobile Test Object Properties is only available with Basic Selection Method

Thanks with Regards


there are few tips to write better selectors (XPaths in this case)

I’m not really sure what are the docs referencing here, but you can use parametrization with both Xpath and CSS locators.