This is an opinion-based question, which is probably why the downvote and the vote for closing the question. In my opinion, getting elements by text is not a good practice mainly because "text" tends to be repetitive. For example, there might be two "OK" buttons on the screen, but you want to test the one at the bottom of the page. However, the getBytext()
will return the first one it finds (top-to-bottom). Finding by XPath (relative position on the DOM) or by ID are better approaches. That said, you will need to consider this when designing and coding your JavaScript code or Angular components. For example, come up with a scheme where IDs won't repeat on a page.
Lastly, if your reply to this is "but that component's text will never change, I will ask you, "Then, why test it?" I would think that a label on a component will have a similar probability of changing than the functionality of the component.