This question already has an answer here:
- What makes a good selenium locator? 6 answers
There is a calculator app calculatoria.com. The task was to create test automation suite for the app. All calculator buttons have unique ids which were used to interact with them.
A button element looks like this
<div class="btnmar btn2" id="btn104" onclick="btnDown(this);"> <a href="#c" class="abtn2 zabtn" onclick="enter(8);blur(this)">8</a> </div>
id="btnXXX" is always unique value for each element
public By digit8Button = By.id("btn104");
When my code is reviewed I got a feedback that I should have used element text (digit) or CSS instead of element id. The argument was that ids can be easily changed but number text is more reliable. This doesn't correspond to many articles I've read while studying test automation about element unique id as the first option to create a good locator.