Although it is not the best solution, sometimes we need to locate elements based on the text displayed. It’s not the best solution if you have to test a multilingual website, because the text is different in every language.
Using XPath we have the following options:
Text equals
//E[text() = 'Displayed text']
Text contains
//E[contains(text(), 'Displayed text')]
Examine your knowledge and play the ‘locator game‘.