2014-03-25 79 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] 
相關問題