2017-12-02 5 views
4

ich diese HTML-Seite haben:XPath wählen Sie Elemente zwischen zwei bestimmten Elementen

<tr class="facts_label"></tr> 
<tr class="facts_label"></tr> 
<tr class="other_label"></tr> 
<tr class="facts_label"></tr> 
<tr class="facts_label"></tr> 
<tr class="other_label"></tr> 
<tr class="other_label"></tr> 
<tr class="facts_label"></tr> 
<tr class="facts_label"></tr> 
<tr class="other_label"></tr> # Select this 
<tr class="other_label"></tr> # Select this 
<tr class="facts_label"></tr> 
<tr class="other_label"></tr> 
<tr class="other_label"></tr> 

Ich möchte die tr-Elemente mit Klasse „other_label“ wählen, die zwischen den letzten 2 tr Elemente mit Klasse „facts_label“ sind

ich habe versucht:

'//tr[@class="other_label" and (preceding-sibling::tr[@class="facts_label"][last()-1]) and (following-sibling::tr[@class="facts_label"][last()])]' 

Aber das ist, was ich habe

<tr class="facts_label"></tr> 
<tr class="facts_label"></tr> 
<tr class="other_label"></tr> # Got this 
<tr class="facts_label"></tr> 
<tr class="facts_label"></tr> 
<tr class="other_label"></tr> # Got this 
<tr class="other_label"></tr> # Got this 
<tr class="facts_label"></tr> 
<tr class="facts_label"></tr> 
<tr class="other_label"></tr> # Got this 
<tr class="other_label"></tr> # Got this 
<tr class="facts_label"></tr> 
<tr class="other_label"></tr> 
<tr class="other_label"></tr> 

Antwort

4

Xpath "Trick":

//tr[ @class='other_label' and count(following-sibling::tr[@class='facts_label'])=1 ] 
+0

, die tatsächlich funktioniert !! .. Vielen Dank Kumpel –

Verwandte Themen