I wonder, how to find out the most recent ancestor of an element.
There are several <h3> tags nested all over the page in different hierarchy levels, and I need to find the ancestor for all of them.
What all of their ancestors share is the first part of the tagname.
So, like this:
Code: Select all
<tag>
<tag>
<PARTTAG...>
<tag>
<h3>
<tag>
<PARTTAG>
<tag>
<tag>
<PARTTAG...>
<tag>
<tag>
<h3>
So my approach is to find the <h3>, then get the ancestor that starts with "PARTTAG" and move on into that.
With something like this:
Code: Select all
/?/?/?/tag[@tagname>'PARTTAG']//h3[@innertext~$myText]/ancestor::tag[@tagname>'PARTTAG']
What I want, is to only find the first recent ancestor.
I tried like this:
Code: Select all
/?/?/?/tag[@tagname>'PARTTAG']//h3[@innertext~$myText]/ancestor::tag[@tagname>'PARTTAG'][][1]
but this seems the find the very first topmost PARTTAG, so it looks like the ancestors array is a flat array and it is just picking the first item out of the array, but I would need the first relative to my h3 tag.
EDIT:
Easy to reproduce:
Code: Select all
/dom[@domain='www.ranorex.com']//h3
-> I would want the 6 most recent ancestor divs where class contains 'blurb' for these h3s
Code: Select all
/dom[@domain='www.ranorex.com']//h3/ancestor::div[@class~'blurb']
Code: Select all
/dom[@domain='www.ranorex.com']//h3/ancestor::div[@class~'blurb'][][1]
Code: Select all
/dom[@domain='www.ranorex.com']//h3/ancestor::div[@class~'blurb'][1][]
Any ideas?
thanks!