Reputation: 1742
I'm using the Ruby Watir library to do automated testing for a client and I'm having issues with the XPath selector. I think I just need another set of eyes to let me know if I'm just missing something.
Here is the selector I'm using:
puts ie.cell(:xpath, "//img[@src='3.jpg']/../").text
For this set of tables, it works as expected and prints "Third Image":
<table>
<tr>
<td><img src="1.jpg">First Image</td>
</tr>
</table>
<table>
<tr>
<td><img src="2.jpg">Second Image</td>
</tr>
</table>
<table>
<tr>
<td><img src="3.jpg">Third Image</td>
</tr>
</table>
But is is breaking when I remove the second table:
<table>
<tr>
<td><img src="1.jpg">First Image</td>
</tr>
</table>
<table>
<tr>
<td><img src="3.jpg">Third Image</td>
</tr>
</table>
Using the puts code above I get this error on the second example:
Watir::Exception::UnknownObjectException: Unable to locate element, using :xpath, "//img[@src='3.jpg']/../"
Upvotes: 1
Views: 1267
Reputation: 6660
For current versions of Watir the better way to do this would be
browser.img(:src => '3.jpg').parent.text
Upvotes: 1
Reputation: 57262
I reproduced the problem, and restarting the browser (IE6) fixed it for me.
Upvotes: 1