在我的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