[英]How to filter parent object which has list of children and a child has list of grand children and by matching property of grand children
[英]How to select grand-grand child (Like 5th OR 6th grand child) element using xpath which has class name only
我正在嘗試選擇第 5 個或第 6 個孫子,它除了類名之外沒有任何其他屬性。 請檢查下面的示例 DOM。
<div id="abc abc abc">
<a>
<a>
<a>
<a>
<a>
</div>
我可以使用 xpath 找到最后一個第五個嗎? 不想使用類似 //div/a/a/a/a/a
在謂詞內部, position()
函數作用於定位器步進軸。 這就是所謂的接近位置。 所以這個 XPath 表達式:
//div[@id='abc abc abc']/descendant::a[5]
意義:
選擇此類
div
元素的第五個a
元素后代
具有此格式良好輸入的表達式:
<div id="abc abc abc">
<a>
<a>
<a>
<a>
<a id="target"/>
</a>
</a>
</a>
</a>
</div>
選擇:
<a id="target"/>
在這里測試
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.