在我的Selenium應用程序中,我嘗試選擇具有最高z-index
的元素。該值不是在元素本身中定義的,而是在祖先節點上定義的(嵌套級別未知)。另外,如果通過使用display: none
不可見祖先,則不應退回。使用XPath選擇具有最高z索引的元素
例HTML:
<div class="container" style="z-index: 10">
<div style="display: none">
<!-- this should not be selected because it is invisible (and the z-index is lower than the others) -->
<div myattr="example"></div>
</div>
</div>
<div class="container" style="z-index: 100">
<div>
<!-- this should not be selected because the z-index is lower than the others -->
<div myattr="example"></div>
</div>
</div>
<div class="container" style="z-index: 1000">
<div>
<!-- this should be selected because it is visible and has the highest z-index -->
<div myattr="example"></div>
</div>
</div>
目前我有一個正則表達式與myattr="example"
選擇所有元件,其不具有與display: none
一個祖先:
//div[@myattr='example'
and not(ancestor::div[contains(@style,'display:none')])
and not(ancestor::div[contains(@style,'display: none')])]
我需要一個附加條件來選擇元件其中Z指數最高,可以說是在其他頂部可見的。對於每個找到的節點,必須查看所有祖先,直到找到具有特定類的節點(本例中爲container
)。然後只返回z-index祖先最高的元素。
這甚至可能與XPath?
僅供參考,我將最初請求的XPath 1.0解決方案添加到我的答案中,以證明它可以做到:)。 – 2013-06-20 10:09:54