HTML tables - help

Ask general questions here.
User avatar
giuseppe.lacagnina
Posts: 113
Joined: Fri Sep 18, 2015 10:25 am
Location: Brunn am Gebirge, Vienna, Austria

HTML tables - help

Post by giuseppe.lacagnina » Fri Nov 10, 2017 12:21 pm

Dear All,

I have been reading some of the documentation pages but I found the solutions a bit confusing.
I am trying to scan all the rows of an HTML table. For each row, I have to read some stuff from the first cell.
I am trying to do this in C#.

I have a table object in the repository but when I try to access the children, it says it is not a table, and yet the repository has,
in the path for the table,

.//table

Could anyone show me a code snippet to do this simple task?

Thanks!!!

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

Re: HTML tables - help

Post by odklizec » Fri Nov 10, 2017 12:38 pm

Hi,

As always, please post a Ranorex snapshot (NOT screenshot) of the table in question. Eventually, post an HTML code we can test. You see, it's much easier to provide a reasonable and spot-on solution with snapshot or sample app/code. 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

User avatar
giuseppe.lacagnina
Posts: 113
Joined: Fri Sep 18, 2015 10:25 am
Location: Brunn am Gebirge, Vienna, Austria

Re: HTML tables - help

Post by giuseppe.lacagnina » Fri Nov 10, 2017 12:39 pm

I am not allowed, unfortunately.

But I am only asking for a generic code to scan all rows from an HTML table. A code snap should not be necessary.

Vaughan.Douglas
Posts: 254
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: HTML tables - help

Post by Vaughan.Douglas » Fri Nov 10, 2017 1:16 pm

giuseppe.lacagnina wrote:I am not allowed, unfortunately.

But I am only asking for a generic code to scan all rows from an HTML table. A code snap should not be necessary.
Unfortunately it may not be as easy as just posting a snippet, but I suspect you might be using the wrong adapter. So the RxPath says .//table you'll need to access it with a tableTAG adapter versus a plain table adapter. See if that doesn't get you past the not a table error.

The reason we ask for a snapshot is to avoid making assumptions that lead people down the wrong path, but I completely understand your restriction. The actual structure of the table can vary widely and what works in one case will simply not work in another. If you've got a simple straightforward table your approach of looping through the descendants should work, we just need the correct adapter. Check out table and tableTag in the API documents.
Doug Vaughan

User avatar
giuseppe.lacagnina
Posts: 113
Joined: Fri Sep 18, 2015 10:25 am
Location: Brunn am Gebirge, Vienna, Austria

Re: HTML tables - help

Post by giuseppe.lacagnina » Fri Nov 10, 2017 1:33 pm

Thanks, will see what i can do :-)

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

Re: HTML tables - help

Post by odklizec » Fri Nov 10, 2017 2:29 pm

Hi,

The closest thing to generic code (related to your matter) can be found here:
https://www.ranorex.com/help/latest/cod ... TableinWeb
In this code you can find a code to loop through HTML table rows.
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

User avatar
giuseppe.lacagnina
Posts: 113
Joined: Fri Sep 18, 2015 10:25 am
Location: Brunn am Gebirge, Vienna, Austria

Re: HTML tables - help

Post by giuseppe.lacagnina » Fri Nov 10, 2017 2:30 pm

Thanks! I am studying it :-)

Vega
Posts: 222
Joined: Tue Jan 17, 2023 7:50 pm

Re: HTML tables - help

Post by Vega » Fri Nov 10, 2017 9:44 pm

Remember that the individual items within an HTML table are not actually table tags, they are things like TR [table row], TH [table header], and TD [table data]. Using the example here:

https://www.w3schools.com/html/tryit.as ... able_intro

You can use a path like this to return all table rows:

/dom[@caption='Tryit Editor v3.5']/body/div[7]/div[4]//iframe[@name='iframeResult']/?/?/table/tbody/tr

The above returns 7 elements

From here, you can navigate up and down the tree using things operators like .. (navigate up to parent) and // (navigate down to children). If you want to return the first table data item (cell) from every row, you can use the below path (this filters out the TH [headers] tags):

/dom[@caption='Tryit Editor v3.5']/body/div[7]/div[4]//iframe[@name='iframeResult']/?/?/table/tbody/tr//td[1]

You can easily adjust these paths to use variables for the indexes or you can return all results and place them in a list:

IList<Ranorex.TdTag> cellList = host.local.find<Ranorex.TdTag>("/dom[@caption='Tryit Editor v3.5']/body/div[7]/div[4]//iframe[@name='iframeResult']/?/?/table/tbody/tr//td[1]");

I hope this helps!

User avatar
giuseppe.lacagnina
Posts: 113
Joined: Fri Sep 18, 2015 10:25 am
Location: Brunn am Gebirge, Vienna, Austria

Re: HTML tables - help

Post by giuseppe.lacagnina » Thu Nov 16, 2017 7:57 am

Hi.
It does indeed. Thanks a lot!!!

G.