Using Selenium IDE, I am trying to locate a link within a table row. The table rows are dynamically generated. Each row has some cell with text content and a cell with possibly two or more links.
What I’d like to do is to create an automated test that clicks a specific link within a specific row as referenced by a specific text. For example, on the table below:
<html>
<body>
<table border="1">
<tr>
<td>
Hello World!
</td>
<td>
Type Greeting
</td>
<td>
<a href="www.foo.com/view/id=123456">View</a>
<a href="www.foo.com/delete/id=123456">Delete</a>
</td>
</tr>
<tr>
<td>
Buenos Dias!
</td>
<td>
Type Greeting
</td>
<td>
<a href="www.foo.com/view/id=789101">View</a>
<a href="www.foo.com/delete/id=789101">Delete</a>
</td>
</tr>
</table>
</body>
</html>
The scenario is, on a previous page I add data “Buenos Dias!”. The next page will display a table of all data added. I want to be able to click on the “View” link of the data that was just added (in this case, the “Buenos Dias!” entry).
What would be a good way to locate the “View” link by referencing the text “Buenos Dias!”?
I am able to locate the cell which contains the text:
//td[text()="Buenos Dias!"]
But I want to use it somehow as a reference for locating its respective “View” link from the table. I tried out sibling formats (following, preceding) and I cant seem to get it to work right. Using an absolute xpath (html/body/table/tbody/tr[1]/td[3]/a[1]) will not work as the data could change and the entry appear on a different row.
Thanks in advance and let me know if you need more information.
- Selenium IDE 1.7.2
- Firefox 9.0.1
- Mac OS X Lion 10.7.3
Use: