Identifying elements without children via RanoreXpath

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
tgroeger
Posts: 13
Joined: Wed Oct 16, 2013 12:43 pm

Identifying elements without children via RanoreXpath

Post by tgroeger » Tue May 27, 2014 1:39 pm

Hello everyone,

I've just come across a rather obstinate problem concerning ranoreXpaths. The following screenshot shows the relevant part of the application I'm working on.
SpyScreenshot.PNG
SpyScreenshot.PNG (137.18 KiB) Viewed 1450 times
I'm trying to create a ranoreXpath which identifies those Containers 'ColumnCell' inside the IosScrollView which have children. Those without children are not showing up on the UI of the application I'm working. The ranoreXpath will then be used in conjunction with a repository variable to identify one of the visible containers by its sequence on the UI.

As an example, the following ranoreXpath would be used if there were no empty containers at all: iosscrollview/container[@platformclass='ColumnCell'][$fieldrowNumber].

- tgroeger

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Identifying elements without children via RanoreXpath

Post by krstcs » Tue May 27, 2014 2:12 pm

If you want only the containers called "ColumnCell" that have children, the following should work:

Code: Select all

iosscrollview/container[@platformclass='ColumnCell']/element/parent::container[$fieldrowNumber]
This will first get all containers with platformclass='ColumnCell', then all element children of those containers (this weeds out the ColumnCells that don't have children because no element will be found under the container), then goes back to the parent container and finds the one with the fieldrownumber indicated.

See if it works. If it does, great! If not, try to tweak it some and see if that works. If you get stumped, let us now how it isn't working and maybe we can help some more.
Shortcuts usually aren't...

tgroeger
Posts: 13
Joined: Wed Oct 16, 2013 12:43 pm

Re: Identifying elements without children via RanoreXpath

Post by tgroeger » Tue May 27, 2014 2:25 pm

The path you specified returns the parent of the first element inside any ColumnCell.

Example:

ColumnCell
- element
- element
ColumnCell
- element
- element
- element
ColumnCell
ColumnCell
- element

Using a variation of your path to get the fourth ColumnCell by using the number 4 as $fieldrowNumber instead returns the parent of the fourth contained element, which would be the second ColumnCell.

Code: Select all

iosscrollview/container[@platformclass='ColumnCell']/element/parent::container[][$fieldrowNumber]
So, sadly, this does not help me.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Identifying elements without children via RanoreXpath

Post by krstcs » Tue May 27, 2014 3:41 pm

I might have misunderstood what you were looking for.

You said that those without children do not show up. Could you instead use the Visible attribute?

Something like:

Code: Select all

iosscrollview/container[@platformclass='ColumnCell' and @visible='True']

And maybe my previous path should have been:

Code: Select all

iosscrollview/container[@platformclass='ColumnCell'][$fieldrowNumber]/element/parent::container
Like I said, you should play with different paths with your application.

Could you post a snapshot of your application (if allowed)? For information on snapshots, see the following:
http://www.ranorex.com/support/user-gui ... files.html
Shortcuts usually aren't...

tgroeger
Posts: 13
Joined: Wed Oct 16, 2013 12:43 pm

Re: Identifying elements without children via RanoreXpath

Post by tgroeger » Wed May 28, 2014 6:20 am

Unfortunately even though those elements aren't discernible on the UI they are nevertheless "Visible" as far as Ranorex is concerned, as can be seen on the screenshot I provided (Invisible items show up as greyed out in the spy).

Code: Select all

iosscrollview/container[@platformclass='ColumnCell'][$fieldrowNumber]/element/parent::container
This ranoreXpath will again, sadly not give me what I need. It will instead give me, out of every ColumnCell, the one with the index $fieldrowNumber and then try to find contained elements. As I've initially written, I need a path that gets any ColumnCell with children a way that I can append a repository variable to call upon those by their sequence.

I appreciate your help and wouldn't be here asking for it if I hadn't tried quite a few ways to do exactly that. If there is another way to identify the elements I need without finding some way to identify elements with or without children I was not able to find it, which is why I'm here asking for a way to do just that.

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

Re: Identifying elements without children via RanoreXpath

Post by odklizec » Wed May 28, 2014 7:18 am

Hi tgroeger,

It would be much easier to help you, if you provide us with the snapshot file of the element in question, as suggested by krstcs.

If I understand you right, then all you need is to identify all non-empty "ColumnCell' elements?

What about this path? This should return ALL nonempty "ColumnCell" elements.

Code: Select all

iosscrollview/container[@platformclass='ColumnCell']/element/parent::container[@platformclass='ColumnCell']
I tried to simulate you problem with the KeePass demo and the above path works quite well for me. It identifies only the ColumnCells with child elements...
ColumnCell.png
ColumnCell.png (66.11 KiB) Viewed 1419 times
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

tgroeger
Posts: 13
Joined: Wed Oct 16, 2013 12:43 pm

Re: Identifying elements without children via RanoreXpath

Post by tgroeger » Wed May 28, 2014 8:43 am

Thank you for your help. I'm unable to provide you with the Snapshot file, because I'm not allowed to do so.

Your path does generally identify the elements I'm searching and was one of the things I've tried beforehand. In practice when using this path I'm unable to access any but the very first ColumnCell that is identified by using it, which is where the problems begin.

I have, before starting this thread, tried three variations of the path you provided which didn't enable me to do what I wanted:

Code: Select all

iosscrollview/container[@platformclass='ColumnCell'][$fieldrowNumber]/element/parent::container[@platformclass='ColumnCell']
This, as stated in an earlier post only enumerates ANY ColumnCell and then searches for contained elements and afterwards itself again, leading to an enumeration of ANY ColumnCell, and not only those with children.

Code: Select all

iosscrollview/container[@platformclass='ColumnCell']/element[][$fieldrowNumber]/parent::container[@platformclass='ColumnCell']
This enumerates any contained elements in any ColumnCell and returns its parent, leading to a false mapping. Instead of returning the second ColumnCell with children when being supplied with "$fieldrowNumber = 2" it instead would return the parent of the second child-element of ANY ColumnCell.

Code: Select all

iosscrollview/container[@platformclass='ColumnCell']/element/parent::container[@platformclass='ColumnCell'][$fieldrowNumber]
This again does the same as the one before it.

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

Re: Identifying elements without children via RanoreXpath

Post by odklizec » Wed May 28, 2014 8:55 am

Without the snapshot, it's really hard to tell what's wrong with your paths or the paths we suggested. OK, would not it be easier for you to create a method with foreach loop that would go through all ColumnCell elements, check the number of their children and do whatever you want to do only with those with non-zero child count?
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

tgroeger
Posts: 13
Joined: Wed Oct 16, 2013 12:43 pm

Re: Identifying elements without children via RanoreXpath

Post by tgroeger » Wed May 28, 2014 9:01 am

It would be a lot easier, provided I only wanted to use that path or the objects a few times in single instances of recordings and/or code. But the path is used as a basepath to specify children inside of specific ColumnCells and subsequently used to define actions on them in the form of recordings.

Not being able to rely on the sole path would mean having to add custom code to quite a few actions and having to add that very same code to any new action I will define in the future, which are and will be quite a few.

Unfortunately it seems that there's no way around it.