Some websites have multiple elements that use the same class names, and provide no unique identifiers. In these cases, your scripts can target a specific element by matching its content with regular expressions, or by using an index as explained below.
For example, consider a page with the following code:
<li class=“red”><a href=”http://www.example.com”>Click Me</a></li>
This would generate something that looks like this:

To click the link with the text "Click Me", you can use the following command:
click(link=regexp:Click Me)
This method might work well enough in cases where the text "Click Me" only appears once on the page, but consider a page that instead has the following code with multiple instances of “Click Me”:
<li class=”red”><a href=”http://www.example.com”>Click Me</a></li>
<li class=”red”><a href=”http://site.example.com”>Click Me</a></li>
<li class=”red”><a href=”http://web.examples.org”>Click Me</a></li>
This code would generate something that looks similar to this:

If you need to click on the third instance of “Click Me,” the previous regex example won’t work. In this case, you can instead use indexes with the XPath to click on the third instance of the class named 'red', by using this command:
click((//a[@class='red'])[3])
This approach also has limitations though, because the number of instances of the class 'red' may change, which may change the indexing of the targeted class. Another option in some cases is to find the element based on text contained in a parent element.
Consider a page with the following code:
<li><a href="http://www.example.com">Click Me</a>First Link</li>
<li><a href="http://site.example.com">Click Me</a>Second Link</li>
This would generate something that looks somewhat like this:

Since both links contain the text "Click Me," you could use a regex to click that text, but since there are multiple instances with that text, a better option is to use the unique text in the "li" tag and then click the anchor tag contained within:
click(//li[@class='red'][contains(text(),'Second Link')]/a)