1

Need to work with the selector with the highest z-index value

<div style="position: fixed;width: 400px;height: 278px;overflow: hidden;box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 6px;bottom: 0px;transition: transform 2s ease 0s;right: 120px;z-index: 2;" class="Cl"><iframe id="t1dxvk58p7cu" name="t1dxvk58p7cu" class="Xyqxtc" allow="camera" style="height: 100%; width: 100%; background: transparent; overflow: hidden; border: none;"></iframe></div>
<div style="position: fixed;width: 400px;height: 278px;overflow: hidden;box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 6px;bottom: 0px;transition: transform 2s ease 0s;right: 120px;z-index: 3;" class="Cl"><iframe id="t1dxvk58p7cu" name="t1dxvk58p7cu" class="Xyqxtc" allow="camera" style="height: 100%; width: 100%; background: transparent; overflow: hidden; border: none;"></iframe></div>
<div style="position: fixed;width: 400px;height: 278px;overflow: hidden;box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 6px;bottom: 0px;transition: transform 2s ease 0s;right: 120px;z-index: 4;" class="Cl"><iframe id="t1dxvk58p7cu" name="t1dxvk58p7cu" class="Xyqxtc" allow="camera" style="height: 100%; width: 100%; background: transparent; overflow: hidden; border: none;"></iframe></div>

I tried below but failed

//div[@class='Cl'][substring-after(@style,'z-index:') > substring-after(../div[@class='Cl']/@style,'z-index:')]
Andersson
  • 51,635
  • 17
  • 77
  • 129
GamiD PC
  • 27
  • 5

1 Answers1

0

Here is an XPath 2.0 solution using regex replace and max

//div[@class='Cl' and replace(@style,'^.*?z-index: (\d+).*?$','$1') = max(../div[@class='Cl']/replace(@style,'^.*?z-index: (\d+).*?$','$1'))]

the main idea is

  • extract the z-index from the style-attribute using replace
  • and compare it to the maximum z-index of similar elements: div[id = max(../div/id)]
    (id equals the extracted z-index)

Live Demo

and here is another one that follows the schema div/[not(..div/id > id)]:

//div[@class='Cl' and not(../div[@class='Cl']/replace(@style,'^.*?z-index: (\d+).*?$','$1') > replace(@style,'^.*?z-index: (\d+).*?$','$1'))]

References:

wp78de
  • 18,207
  • 7
  • 43
  • 71
  • @GamiDPC Sorry, Chrome uses XPath 1.0. https://stackoverflow.com/a/25455588/8291949 See https://bugs.chromium.org/p/chromium/issues/detail?id=689271 – wp78de Nov 06 '18 at 20:55
  • And you can redo it to work in chrome, but I did not understand what to do. – GamiD PC Nov 06 '18 at 21:25
  • @GamiDPC no, since XPath 1.0 does not support regular expressions and I do not see a way to rewrite this without extraction the z-index. Your best bet is to use a programming language like (like JS, Python, etc.) to handle the extraction on comparison of all selected divs. – wp78de Nov 06 '18 at 21:42