使用xpath选择<input />标记后面的第一个<img/>标记

时间:2013-03-28 14:27:44

标签: html xpath

我有以下HTML:

<root>
 <Customer cid= "C1" name="Janine" city="Issaquah">
  <input name="Client.ClaimsAdjudicationPendReason" />
  <a onclick="javascript:pendReasonLookup('MFM_Pend Reason', 'PendReason','txtClaimsAdjudicationPendReason','','')>
            <img title="Lookup" class="imgSearchIcon" alt="Lookup" src="/F005web/images/search.gif"/>


<input name="Client.ClaimsAdjudication" />
    <a onclick="javascript:pendReasonLookup('MFM_Pend Reason', 'PendReason','txtClaimsAdjudication','','')>
            <img title="Lookup" class="imgSearchIcon" alt="Lookup" src="/F005web/images/search.gif"/>

  </Customer>  
</root>

使用下面的xpath,我可以选择'input'节点

name="Client.ClaimsAdjudicationPendReason"

xpath:=//input[@name='Client.ClaimsAdjudicationPendReason']

但我需要选择img节点(位于a标签下方)

name="Client.ClaimsAdjudicationPendReason"

1 个答案:

答案 0 :(得分:0)

原来的html有些缺失,请参阅上面的评论。所以假设这是预期的:

<root>
    <Customer cid="C1" name="Janine" city="Issaquah">
        <input name="Client.ClaimsAdjudicationPendReason" />
        <a onclick="javascript:pendReasonLookup('MFM_Pend Reason', 'PendReason','txtClaimsAdjudicationPendReason','','')" />
        <img title="Lookup" class="imgSearchIcon" alt="Lookup" src="/F005web/images/search.gif" />
        <input name="Client.ClaimsAdjudication" />
        <a onclick="javascript:pendReasonLookup('MFM_Pend Reason', 'PendReason','txtClaimsAdjudication','','')" />
        <img title="Lookup" class="imgSearchIcon" alt="Lookup" src="/F005web/images/search.gif" />
    </Customer>
</root>

下面的xpath将在img input之后选择第一个name节点“Client.ClaimsAdjudicationPendReason”

//input[@name="Client.ClaimsAdjudicationPendReason"]/following-sibling::img[1]