How to locate a parent element which contains another element
For example:
I have the following structure:
<td>
<a>
<input id="MyID1">
</td>
<td>
<a>
<input id="MyID2">
</td>
<td>
</td>
We suggest that <a>
does not have any specific attributes to locate it by them.
So 2 questions:
I need to locate
<a>
in second td. I know that<a>
Im looking for is placed to the same td with "MyID2" input. How can I do that?I need to locate 3rd td (empty). I know that td Im looking for is the following td for td what开发者_如何学编程 contain "MyID2" input. How can I do that?
Thanks!
If you can use XPath somewhere, the following expression will find the <a>
element in the second <td>
:
//td/a[../input/@id='MyID2']
It will find all <a>
elements, which are direct children of a <td>
element having an <input>
element on the same level with an id attribute equal to 'MyID2'.
精彩评论