Reputation: 73
I am trying to come up with an xpath to locate the text in the span that says text to locate in the second portion of the xpath
by first locating an image in a tr in a td in a table in the div below it.
This is the HTML structure (simplified/pseudocode):
<table>
<tbody>
<tr>
<td>
<span>id to locate in the second portion of the xpath
</span>
</td>
</tr>
</tbody>
</table>
<div>
<table>
<tbody>
<tr>
<td>
<img>imgPartStatus</img>
</td>
</tr>
</tbody>
</table>
These are my attempts:
//tr[starts-with(td/img[contains(@id,'imgPartStatus')])]preceding::(table/tbody/tr/td/span[contains(@id,'idto locate in the second portion of the xpath')])
//tr[starts-with(td/img[contains(@id,'imgPartStatus')])]sibling::(table/tbody/tr/td/span[contains(@id,'idto locate in the second portion of the xpath')])
So the first portion //tr[starts-with(td/img[contains(@id,'imgPartStatus')])]
is already covered and works fine. But I need to step out of that img, td, tr, table, out of the div, and look in the table above. Makes sense? Thank you for checking out my question.
Also, not sure about the title's "Sibling table". It may not be called that way. Sorry!
Upvotes: 0
Views: 201
Reputation: 73
It took a bit of time but here it is:
//div[starts-with(table/tbody/tr/td/img[contains(@id,'imgPartStatus')]/preceding::table[1]/tbody/tr/td/span[contains(@id,'idto locate in the second portion of the xpath')]
Upvotes: 1