Page 1 of 1

How do I get next row using RanoreXPath

Posted: Sat Oct 02, 2010 11:44 am
by markvanraalte
Hi,

I want to get an element that points to the next row in a table on a web page, based on a text match of the previous row. I am using Visual Studio / C#.

For example,
I have the following relative path "./table/tbody/tr[@class='header']/th[@innertext='MySelectedRow']" where I am matching on the word: 'MySelectedRow'

I have tried to get the following row using this expression:
"./table/tbody/tr[@class='header']/th[@innertext='MySelectedRow']/../following-sibling::*"

Unfortunately this path matches ALL the subsequent rows instead of just the next one. Is it possible to change this to get just the NEXT row?

Regards
Mark

Re: How do I get next row using RanoreXPath

Posted: Sat Oct 02, 2010 8:03 pm
by sdaly
You could try something like this...

Dim selectedRow as Ranorex.whateveritis = "/path for matching row"

Dim row as Interger = selectedRow.Row + 1

Dim nextRow as Ranorex.whateveritis = "/path filtered on row attribute matching row integer"

Re: How do I get next row using RanoreXPath

Posted: Mon Oct 04, 2010 10:06 am
by Support Team
Hi,

Please also take look to following post
http://www.ranorex.com/forum/webtable-r ... t1661.html

Regards,
Peter
Ranorex Team

Re: How do I get next row using RanoreXPath

Posted: Mon Oct 04, 2010 6:22 pm
by markvanraalte
Thanks Peter and Sdaly,

I was hoping to find a solution using RanorexPath to select the row based on a match of the previous row.
Using the solution provided unfortunately I would have to modify the code, so that I:

1: Loop through all the rows in the table
2: When I find a match, then proceed to the next row and retrieve the values

Now my code is quite generic, being used on different webPages and data driven via the RxPath, therefore I would prefer to use the path to match on the row if possible, but it looks like it cannot be done.

Incidentally I cant even see how I would get the row number of a matched row without counting through all the rows till I find the match?

Mark.

Re: How do I get next row using RanoreXPath

Posted: Tue Oct 05, 2010 9:02 am
by Support Team
Hi Mark,

Sorry I read over the following line. "./table/tbody/tr[@class='header']/th[@innertext='MySelectedRow']/../following-sibling::*" :)
Of course it is possible to use the RxPath to get the next row, you can use your RxPath, just correct the last statement to "./table/tbody/tr[@class='header']/th[@innertext='MySelectedRow']/following-sibling::*".

Regards,
Peter
Ranorex Team

Re: How do I get next row using RanoreXPath

Posted: Tue Oct 05, 2010 8:50 pm
by markvanraalte
HI Peter,

What you are suggesting below does not work. Try it youself.

Using the Spy tool I have an example on www.ranorex.com page.

go to this page and look at the table of items under the title: "Benefit with Ranorex".

Lets say I want to get the next row that appears under the item "Excellent Object Recognition"

I use the following path:
/dom[@caption~'^Test\ Automation\ Tools\ -\ R']/body/div[@id='page']/div[@id='container']/div[@id='Content']/div[1]/div[1]/ul/li[1]/a/b[@innertext~'^Excellent\ Object\ Recognit']/../../following-sibling::*

This path returns ALL following siblings. Show me a path that will get just the NEXT sibling?

Regards
Mark

Re: How do I get next row using RanoreXPath

Posted: Wed Oct 06, 2010 8:39 am
by Support Team
markvanraalte wrote:This path returns ALL following siblings. Show me a path that will get just the NEXT sibling?
That is by design of XPath, your path matches all following siblings. Depending on the method you use to search for the path, you will get the first element (FindSingle) or all elements (Find) matching the RanoreXPath.

When you use the path in a Ranorex repository, the repository will return only the first element - and I guess that's exactly the behavior you want, right? E.g. for the example on the Ranorex web site you could use the following line of code:
Unknown nextSibling = "/dom[@caption~'^Test\ Automation\ Tools\ -\ R']/body/div[@id='page']/div[@id='container']/div[@id='Content']/div[1]/div[1]/ul/li[1]/a/b[@innertext~'^Excellent\ Object\ Recognit']/../../following-sibling::*";
Regards,
Alex
Ranorex Team