Create repo item of parent element based on child attribute

Ask general questions here.
semate
Posts: 5
Joined: Tue Jul 03, 2018 7:42 am

Create repo item of parent element based on child attribute

Post by semate » Fri Nov 23, 2018 1:14 pm

Is it possible to select a item in the repository based on an attribute of the child element? For example to select the element of the 'dataGroup' container item which is the parent of the Text item with the Caption "Thumbnails" (see below)
RepoImg.PNG
RepoImg.PNG (17.84 KiB) Viewed 41 times
I tried:

Code: Select all

toolbar[@id='buttonBarViewMode']//text[@caption='Thumbnail']/../../../element
which gave me back an element, but the wrong one (=always the same, no matter what caption is set to)

Code: Select all

toolbar[@id='buttonBarViewMode']//element/..//text[@caption='Thumbnail']
which gave me back the text element (child)

Thanks!

P.S.: I do know how to solve it in C# and sure, I could use the different element names - but that's not the point.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 4041
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Create repo item of parent element based on child attribute

Post by odklizec » Fri Nov 23, 2018 1:25 pm

Hi,

It may be possible to solve your problem with xpath relationship operators. But it's hard to say without seeing, at very least, Ranorex snapshot of the UI. Could you please post the snapshot (NOT screenshot) of the problematic toolbar?

From the screenshot, I can only guess that the xpath you are looking for should look like this:

Code: Select all

toolbar[@id='buttonBarViewMode']//text[@caption='Thumbnails']/ancestor::container[@class='dataGroup']
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration