Page 1 of 1

Identification issue on nested child items

Posted: Wed Sep 22, 2021 1:47 pm
by mrt
Dear folks,

I try to dynamically identify nested child elements and have issues finding a RXpath for the following structure of the application

Code: Select all

tag
--div
----tag
tag
--div
----div
tag
--div
----div
...
What i want to skip is the first tag/div/tag and get only the tag/div/div items, and - here comes the tricky part - identified by their number because there are absolutely no attributes to make use of.

so I am searching for: How to identify the first, the second tag/div/div element?

Code: Select all

tag[1]/div/div
does not find any element, because it searches for 2 divs in the first tag, which is not there.

Code: Select all

tag/div[1]/div
also does not work, because it searches inside the first tag.

What I am looking after is something like the first occurrence of "tag/div/div" element.
Something like (tag/div/div)[1] (pseudocode)

Any ideas?

thanks!

Re: Identification issue on nested child items

Posted: Wed Sep 22, 2021 2:47 pm
by odklizec
Hi,

Please provide a Ranorex snapshot with example of structure you are working with. It's hard to suggest something sensible without snapshot ;)

Re: Identification issue on nested child items

Posted: Thu Sep 23, 2021 7:28 am
by mrt
Hey,

sorry, a snapshot would contain too much sensible information.
If you have any detailed questions I would be please to answer, but I can't post a snapshot online.

Is it somehow possible to combine multiple elements to one "object recognition bundle"?

Re: Identification issue on nested child items

Posted: Thu Sep 23, 2021 7:35 am
by odklizec
Well, I'm afraid that without snapshot, it's impossible to suggest anything reliable. Can't you create a small sample web page, mimicking your situation? Or save the page you are working on and strip it of all sensitive data :D

I personally don't see what's wrong with tag/div/div xpath, although I agree it's useless, if there are multiple elements found. In this case, I would use whatever property from given element, or even property of ancestor/descendant elements, to uniquely identify the element in question. But as said, I can't help more without snapshot or sample page.

Re: Identification issue on nested child items

Posted: Thu Sep 23, 2021 8:00 am
by mrt
Hmm, I know it is hard to suggest anything without knowing the AUT.
Stripping would take ages because even the custom tagnames are treated as sensitive ...

I try to explain further:

What this is all about, is comparing elements in a table with known values.
But - of course that would be too easy - it is not a table webelement, it has no table capabilities, there are no IDs or other unique properties for any cell.
It is just a bunch of divs basically.
Headers are not linked in any way to data cells, all needs to be built up by hand.

In addition, the tests have to run in 2 different environments (A, B) , which are basically the same except the fact, that there is an additional icon column added as first column in environment B, which i need to skip.

So, in environment A this table looks like:

Code: Select all

Column 1  |  Column 2  |  Column 3  |  ...
value1    |  value2    |  value3    |  ...
environment B looks the same, but has an icon colum added as first column:

Code: Select all

Icon  |  Column 1  |  Column 2  |  Column 3  |  ...
      |  value1    |  value2    |  value3    |  ...

In environment A the data row looks like:

Code: Select all

<dataRow>
  <tag>          --> data cell
    <div>
      <div>      --> value1
      
  <tag>          --> data cell
    <div>
      <div>      --> value2
   ...
and in environment B:

Code: Select all

<dataRow>
  <tag>          --> icon cell
    <div>
      <tag>
      
  <tag>          --> data cell
    <div>
      <div>      --> value1
      
  <tag>          --> data cell
    <div>
      <div>      --> value2
   ...
So for environment A the cell values could be easily linked statically as repository items like:

Code: Select all

tag[1]/div/div          --> value1
tag[2]/div/div          --> value2
...
which does not work anymore in environment B, because tag[1]/div/div is not found there.

Without making situation more complicated and using different recording and other code-based stuff I would like to set the RXpath accordingly, so object recognition works in each of these environments.

Is this more understandable now? :)

Re: Identification issue on nested child items

Posted: Thu Sep 23, 2021 8:21 am
by odklizec
Yes, I understand. Sadly, without the possibility to actually see the snapshot/UI via Spy, I can't help you much. I just need to see and try it ;)

What I'm doing in similar situations (with UI without useful attributes), is to get the child index of column header (this should be easily identifiable by header name?) and then find the problematic cell with value I want to compare, via the obtained childindex. I assume that the cell has the same childindex? In some cases, it requires +/- 1. But this is not something you can do with simple xpath. You will have to do it in two steps. First, use the GetValue action, to get the childindex of header cell and store it in variable. If the target cell chindindex requires +/- adjustment, you will have to do it in user code. And then use the variable in xpath, stored in repo. Hope this helps?

Re: Identification issue on nested child items

Posted: Thu Sep 23, 2021 8:30 am
by mrt
Yes, I did exactly that for another application and it works quite well, but as you said, multiple steps are needed which also involve user code and I didn't want to put that much effort in.

But, I guess I will have to go that way, thanks.