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!!!
HTML tables - help
- giuseppe.lacagnina
- Posts: 113
- Joined: Fri Sep 18, 2015 10:25 am
- Location: Brunn am Gebirge, Vienna, Austria
Re: HTML tables - help
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.
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 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
- giuseppe.lacagnina
- Posts: 113
- Joined: Fri Sep 18, 2015 10:25 am
- Location: Brunn am Gebirge, Vienna, Austria
Re: HTML tables - help
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.
But I am only asking for a generic code to scan all rows from an HTML table. A code snap should not be necessary.
-
- Posts: 254
- Joined: Tue Mar 24, 2015 5:05 pm
- Location: Des Moines, Iowa, USA
Re: HTML tables - help
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.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.
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
- giuseppe.lacagnina
- Posts: 113
- Joined: Fri Sep 18, 2015 10:25 am
- Location: Brunn am Gebirge, Vienna, Austria
Re: HTML tables - help
Thanks, will see what i can do
Re: HTML tables - help
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.
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 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
- giuseppe.lacagnina
- Posts: 113
- Joined: Fri Sep 18, 2015 10:25 am
- Location: Brunn am Gebirge, Vienna, Austria
Re: HTML tables - help
Thanks! I am studying it
Re: HTML tables - help
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!
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!
- giuseppe.lacagnina
- Posts: 113
- Joined: Fri Sep 18, 2015 10:25 am
- Location: Brunn am Gebirge, Vienna, Austria
Re: HTML tables - help
Hi.
It does indeed. Thanks a lot!!!
G.
It does indeed. Thanks a lot!!!
G.