2014-03-25 80 views
1

我正在尝试为我的自动测试创建一个xpath。我有以下代码:Xpath如何使用另一个元素文本值获取一个元素

<span class="left-floated"> 
    <input class="PfcExecutiveBrief" type="checkbox" value="PfcExecutiveBrief" name="DocumentTypeResearch"/> 
    <label for="PfcExecutiveBrief">Executive Brief</label> 
    <br/> 
    <input class="Memo" type="checkbox" value="PfcMemo" name="DocumentTypeResearch"/> 
    <label for="PfcMemo">Memo</label> 
    <br/> 
    <input class="PfcOtherResearchForNaturalGasOrOil" type="checkbox" checked="checked" value="PfcOtherResearchForNaturalGasOrOil" name="DocumentTypeResearch" disabled=""/> 
    <label for="PfcOtherResearchForNaturalGasOrOil">Other Research</label> 
    <br/> 
    <input class="PfcProfile" type="checkbox" value="PfcProfile" name="DocumentTypeResearch"/> 
    <input type="hidden" value="PfcOtherResearchForNaturalGasOrOil" name="DocumentTypeResearch"/> 
    <label for="PfcProfile">Profile</label> 
    <br/> 
</span> 

我想创建xpath帮助我检查所选标签的输入元素。所以我的问题是,如何为每个标签获得单个输入元素?

例如,如果:

label[text()='Memo'] 

如何让第二个输入等等,等等。

回答

2

虽然@for属性在这里被滥用(it should point to the @id attribute),你可以用它来解决,以匹配输入使用相同的@value属性。

//input[@value=../label[text()='Memo']/@for] 

如果标签可能是无处不在文件中(而不是被你的例子像兄弟姐妹),你也可以从根本上重新搜索:

//input[@value=//label[text()='Memo']/@for] 
相关问题