For a software test I need to find out the ID or rather the specific integer of "parentid" of a div container. My first idea was to filter for the value "1" to get inside the correct div block. Since this is also a unique element, this works. However, now I am wondering what is the best way to navigate back relatively to the correct parent div block to get me the ID.
Can someone maybe help me here? below is also a picture for a better understanding.
best regards Andreas
CodePudding user response:
Please make use of ancestor
like below with starts-with
method, there is not need to use contains
, since we are just looking for parentid
.
//*[@value='1']/ancestor::div[starts-with(@id,'parentid')]
In case you would like to have the entire parentid
, please use this :
//*[@value='1']/ancestor::div[@id='parentid_593']
or in general you can write /..
to go to parent node from current node. so
//*[@value='1']/../../../../..
should get the job done, but it looks brittle. Please use the first one.