2014-05-13 82 views
1

好吧,首先代码:另一个Xpath的困境

<tr class="tableControlDataRow evenRow twTableTR"> 
<td class="twTableTD details" align="center" rowspan="2"> 
<td class="twTableTD details" align="center" rowspan="2"> 
    <p> 
    <br> 
    **<p>** 
     <b>Model Number:</b> 
     QA GM 05132014 1038 Item 1 Model Number 
    </p> 
    <p> 
    <p> 
    <p> 
    <p> 
</td> 
<td class="twTableTD" align="center" rowspan="2">May-27-2014</td> 
<td class="twTableTD" align="center">France</td> 
<td class="twTableTD" align="center">Yes</td> 
<td class="twTableTD" align="center"> 
    <input id="hiddenCountryAuthorizationField0_0" type="hidden" name="tw#local#quoteComparison#0#country#0#authorizationStatusId#" value="0"> 
    <input id="CountryAuthorizationYES0_0" class="qclCheckbox" type="checkbox" onclick="chooseAuthorization(0,0,'Yes','1')"> 
    Yes 
    <br> 
    <input id="CountryAuthorizationNO0_0" class="qclCheckbox" type="checkbox" onclick="chooseAuthorization(0,0,'No','2')"> 
    No 
    <br> 
</td> 

现在的问题......我已经做了

//p[contains(., "QA GM 05132014 1038 Item 1 Model Number")] 

这让我的**部分找到正确的出发点的代码。现在我需要遍历到<tr class="tableControlDataRow evenRow twTableTR">顶部,然后乘车返回环比下跌点击

<input id="CountryAuthorizationYES0_0" class="qclCheckbox" type="checkbox" onclick="chooseAuthorization(0,0,'Yes','1')"> 

文本框。有什么建议么?

回答

2

首先找到tr,有p标记提供相应的文本,然后再往所需input

//tr[.//p[contains(., "QA GM 05132014 1038 Item 1 Model Number")]]/td/input[@id="CountryAuthorizationYES0_0"] 

只是注意,肯定有多种方式写在这里的XPath的。希望这一个适合你。

+0

试过在FirePath并没有返回匹配的节点... – GregMa

+0

@GregMa可能大家分享一个链接到你解析的页面? – alecxe

+0

它是内部的,所以不能。但我确实弄清楚了。看起来像我粘贴的代码是不正确的。我使用@id,'CountryAuthorizationYES',它工作。 – GregMa

0

我也建议//p[contains(text(),'QA GM 05132014 1038 Item 1 Model Number')]/ancestor::tbody[1]//input[@id='CountryAuthorizationYES0_0']。它将搜索包含'QA GM 05132014 1038 Item 1 Model Number'文本的元素,然后搜索第一个父元素tbody,然后搜索从第一个(父)tbody开始的所需输入

0

这并不美观,但此代码可能有帮助你:

//p[contains(., "QA GM 05132014 1038 Item 1 Model Number")]//parent::br/parent::td/parent::tr//input[@id='CountryAuthorizationYES0_0']