Reputation: 63
I'm in a bit of a struggle with finding and clicking a specific link. All links in a HTML table contain the word 'Edit' (it's an 'Edit' link for a configuration setting). However, the link varies per environment I'm working on, so only the 'Edit' bit of the link is consistent.
In the HTML of the page, I found that this link is part of a table also containing the configuration setting that I want to edit. I've been struggling for a few hours now to find this link through Xpath, through CSS... Basically I need someone's help on this. Hence my post here!
The HTML of the page looks like this (I anonymized it -- is that even a word?):
<table>
<thead>
<tr>
<th>edit</th>
<th>Name</th>
<th>Value</th>
<th>Label</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="/configurations/406/edit">Edit</a></td>
<td>Configuration 1</td>
<td>This is its value</td>
<td>This is its explanation</td>
</tr>
<tr>
<td><a href="/configurations/327/edit">Edit</a></td>
<td>Configuration 2</td>
<td>This is its value</td>
<td>This is its explanation</td>
</tr>
<tr>
<td><a href="/configurations/328/edit">Edit</a></td>
<td>Configuration 3</td>
<td>This is its value</td>
<td>This is its explanation</td>
</tr>
</tbody>
</table>
Can someone please give me some pointers as to how I can get to each 'Edit' link, based on the 'configuration'?
Thanks a lot in advance. It will really save me a headache!
Upvotes: 1
Views: 44
Reputation: 49870
You can scope Capybaras finds and actions to other elements, therefore
find(:css, 'tr', text: 'Configuration 2').click_link('Edit')
would click the edit link inside the tr that includes the text 'Configuration 2'
Upvotes: 1