I’m trying to write Selenium tests for HTML that’s structured like this:
<table>
<tr id="row-1">
<td><span class="some_data">what I'm looking for</span></td>
<td><button class="doSomething" onclick="..."></button></td>
</tr>
<tr id="row-n">
<td><span class="some_data">not what I'm looking for</span></td>
<td><button class="doSomething" onclick="..."></button></td>
</tr>
</table>
I need the test to click the button that’s in the same row as what I'm looking for. I can find the span that it’s in (driver.find_elements_by_xpath('//span[text() = "what I'm looking for"]')), but I don’t know how to get from there to the corresponding button.
I’m using the Selenium Python bindings, version 2.21.2.
Try:
If finds the
trwhich has atd/spanwith the text “what I’m looking for”, then moves from thattrto thetd/buttoninside it.