Page 1 of 1

Problems using 'following-sibling'

Posted: Wed Apr 30, 2014 4:34 pm
by Aracknid
Hi,

I'm using Ranorex 4.06. Here's my problem (or perhaps failure to understand how this works)

As an example, I have a parent element (Body) that contains multiple DIV children. Some of these DIV's have an ID and one doesn't. It happens that the DIV I want to find doesn't, but the one just before it does.
Example.jpg
So I can find the DIV before it no problem and store it in "MyDiv" which is a DivTag object.

Now to get the next div, I have tried

Code: Select all

MyNewDiv = MyDiv.nextsibling 
(which returns nothing) and I have tried this:

Code: Select all

MyNewDiv = MyDiv.FindSingle("./following-sibling::div",5000)
And this returns the first div in parent element which is not the right one at all.

If I go into Spy and the Xpath is showing MyDiv, if I modify it to append to the xpath 'following-sibling::div', Spy will show will ALL the Divs in the parent. Some of these divs are BEFORE MyDiv and one is after (the one I want).

The instructions say that Following-sibling refers to ALL siblings after the current node. I was under the impression my current node was MyDiv, not it's parent.

Why doesn't this work, or do I not get it?

Oh, and I'm not looking for another way to get the element. I know how to do it. I really want to know why following-sibling isn't work as I expect it to.

Aracknid

Re: Problems using 'following-sibling'

Posted: Fri May 02, 2014 4:02 pm
by Support Team
Hi Aracknid,

There was already a similar problem discussed in this forum.
My I ask you to have a look at this two posts:
Preceding-sibling last()
How do I get next row using RanorexPath

In this two posts the following-sibling method is explained in detail and it might be very useful for you.

Please let me know if this helps to solve your problem.

Kind regards,
Markus (S)

Re: Problems using 'following-sibling'

Posted: Fri May 02, 2014 6:38 pm
by Aracknid
The other postings (specifically the first one you mention) explains it exactly as I expected it should work. I understand it. My issue is that in my example it is NOT working like that. Look at my attached image. The 4th DIV in the list is the one in my xpath (in spy) that is then followed by the 'following-sibling::div'. According to how it should work, it should only show me ALL the Divs AFTER the 'Master_IdHeaderContainer' DIv, but it shows me some that appear before it as well.

So I tried 'preceding-sibling::div', expecting it to work like you example and it finds no matches.

This leads me to believe that even though SPY shows it as the 4th DIV it is actually the first. Is that possible?

Re: Problems using 'following-sibling'

Posted: Fri May 02, 2014 8:32 pm
by KurtZ
Hi Aracknid,
I can reproduce the same thing you are showing with Div object in one of my webpages. The problem lies somewhere in the combination of the relative path, the hashtag, and the following-sibling::div.

If you were to do any of these paths, following(preceding)-sibling should work like you expect:
"./body/iframe/body/div[#'Master_IdHeaderContainer]/following-sibling::div"
"./body/iframe//self::div[#'Master_IdHeaderContainer]/following-sibling::div"
"./body/iframe//div[@attribute='Master_IdHeaderContainer]/following-sibling::div"
Sorry I don't know the exact asnwer, but perhaps this will point another poster in the right direction.

Re: Problems using 'following-sibling'

Posted: Fri May 02, 2014 9:06 pm
by Aracknid
Interesting. I added "self::" before my reference div and it solved the problem in SPY.

E.G. self::div[#'Master_IdHeaderContainer]/following-sibling::div"

How do I make this work in code.

I have MyDiv, which is 'div[#'Master_IdHeaderContainer]'

Normally, I'd do MyNewDiv = MyDiv.FindSingle("./following-sibling::div")

Should I do something like this?

MyNewDiv = MyDiv.FindSingle("self::div/following-sibling::div")

Thanks for the help.

Aracknid

Re: Problems using 'following-sibling'

Posted: Fri May 09, 2014 2:39 pm
by Support Team
Hi Aracknid,

I was able to reproduce your issue.
Using the unique id in combination with following sibling will cause a wrong result.
As a workaround I would suggest to use div[@attribute=’VALUE’]/following-sibling::div. This should return the correct divTags.

This issue will be fixed in one of our next releases.

Regards,
Markus (S)