开发者

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:

  1. 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?

  2. 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'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜