Table Row Iteration

Best practices, code snippets for common functionality, examples, and guidelines.
theraviz
Posts: 34
Joined: Sun Apr 14, 2019 9:46 am

Table Row Iteration

Post by theraviz » Thu Sep 05, 2019 12:21 pm

Hello,

I have to get one cell value from a table and I don’t know how to iterate through table rows and cells. Can somebody please provide the code?

Idea is to perform a row wise check for a specific token number (column is known). If found, I have to retrieve the value of the cell which is after 3 cells to the token cell.

Please help

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

Re: Table Row Iteration

Post by odklizec » Thu Sep 05, 2019 12:26 pm

Hi,

Please upload a Ranorex snapshot (NOT screenshot) of given table. Thanks.
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

theraviz
Posts: 34
Joined: Sun Apr 14, 2019 9:46 am

Re: Table Row Iteration

Post by theraviz » Thu Sep 05, 2019 1:06 pm

Thank you. File Attached. Please check
table.rxsnp
(280.06 KiB) Downloaded 8 times

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

Re: Table Row Iteration

Post by Support Team » Thu Sep 05, 2019 9:38 pm

Hi theraviz,

We can navigate to the row containing the specific token number with the example RxPath below. Just change out TOKENNUMBER with the actual number you are looking for. You can also use a repository variable here.

Code: Select all

/dom[@domain='10.222.124.90']//table[#'JournalTableData']//td[@innertext='TOKENNUMBER']/parent::tr
From here, what are you wanting to grab? I assume something from another column but in the same row. If you can specify specifically what you are trying to grab, I will be happy to provide an RxPath to do this. For example, the RxPath below points to the User cell in the same row as the token number.

Code: Select all

/dom[@domain='10.222.124.90']//table[#'JournalTableData']//td[@innertext='TOKENNUMBER']/parent::tr/td[@txfield='TellerId']
I hope this helps!

Cheers,
Ned
.
Image

User avatar
Vega
Posts: 161
Joined: Mon Jul 11, 2016 2:15 pm

Re: Table Row Iteration

Post by Vega » Thu Sep 05, 2019 9:39 pm

there are some code examples on validating an entire table / web table at once:

Advanced validation – entire table
Advanced validation – entire table in web
https://www.ranorex.com/help/latest/han ... -examples/

however this is for an entire table so this may be overkill for what you need. You can modify your XPath to traverse up or down the tree from the element which is known (token). I'm not sure exactly which cell you are trying to find, but I can give an example based on the snapshot:

Lets assume we know the 'From/To No.' ahead of time and we can use this to retrieve the 'Trace Number' from the same table row, here is how I would do it:

/dom[@domain='10.222.124.90']//table[#'JournalTableData']//td[@innertext='2020196560']/../td[6]

So as you can see above, we first find a td element with the innertext of '2020196560', this is our known starting point for the 'From/To No.' value. Of course this would likely be a variable within your test, but for this example I am using static values. Next you will see in the path that I am using /../td[6]. The '..' means go up the tree to the parent node which would be the table row, then /td[6] tells Ranorex to give us the 6th TD element in that row which happens to be the 'Trace Number'


hope this helps

theraviz
Posts: 34
Joined: Sun Apr 14, 2019 9:46 am

Re: Table Row Iteration

Post by theraviz » Tue Sep 17, 2019 9:24 am

Thanks :)