How do I get next row using RanoreXPath

Class library usage, coding and language questions.
markvanraalte
Posts: 13
Joined: Thu Apr 15, 2010 4:34 pm

How do I get next row using RanoreXPath

Post by markvanraalte » Sat Oct 02, 2010 11:44 am

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

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: How do I get next row using RanoreXPath

Post by sdaly » Sat Oct 02, 2010 8:03 pm

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"

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How do I get next row using RanoreXPath

Post by Support Team » Mon Oct 04, 2010 10:06 am

Hi,

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

Regards,
Peter
Ranorex Team
.
Image

markvanraalte
Posts: 13
Joined: Thu Apr 15, 2010 4:34 pm

Re: How do I get next row using RanoreXPath

Post by markvanraalte » Mon Oct 04, 2010 6:22 pm

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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How do I get next row using RanoreXPath

Post by Support Team » Tue Oct 05, 2010 9:02 am

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
.
Image

markvanraalte
Posts: 13
Joined: Thu Apr 15, 2010 4:34 pm

Re: How do I get next row using RanoreXPath

Post by markvanraalte » Tue Oct 05, 2010 8:50 pm

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How do I get next row using RanoreXPath

Post by Support Team » Wed Oct 06, 2010 8:39 am

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
.
Image