I has a page as follow:
<table>
<tr>
<th>Company Name</th>
</tr>
<tr>
<td><a href="www.whatever.com"> What Ever Company</a></td>
</tr>
</table>
The company name is placed arbitrary in the table, so I can only use the link’s text to locate the link:
selenium.click("link='What Ever Company'");
However, it says: ERROR:Element link='What Ever Company' not found.
What is the problem here? Is there any other way to click on the link?
Many thanks.
EDIT
Seem that the problem is I have several links with the same text (my bad). After making the link’s text unique, I use selenium.click("//a[contains(text(),'Test Campaign 1756237989')]") and it works.
Could this be because you’re forgetting the space at the start of the link?
Another possible way of clicking the link, is to use an XPath expression:
This will match all links with ‘What Ever Company’ in it.
If you want it more exact:
This will only match if the anchor equals ‘ What Ever Company’.
Another option is to make the search more specific (i.e. tell the locator this link is always inside a
<td>with an<a>inside):The
//td[a]looks for all<td>elements with<a>inside. (Differs from//td/ain that if you look for elements with//td[a][2]you get the second<a>which is inside a<td>, while//td/a[2]on the other hand gets the second<a>of the first<td>.)EDIT: I thought using
.as a reference totext()in the XPath expressions should work, but if it doesn’t, try usingtext()instead.