Read HTML Table Row

Class library usage, coding and language questions.
maamer
Posts: 23
Joined: Fri Nov 30, 2018 6:03 pm

Read HTML Table Row

Post by maamer » Mon Feb 04, 2019 11:01 pm

Hello All,

I am Trying to read an HTML table. the columns in this table can be interchanged.
aVwdI-1.png
aVwdI-1.png (28.84 KiB) Viewed 391 times
i am interested only in the Report ID column. My test case is click on view button (under Action column) of each report under Report ID. so iam trying to write a sample code for this.

Code: Select all

var repo = BottomLineIIRepository.Instance;
 var tdTag601147168EDI = repo.DigitalBanking.LegacyReports.tablerows;
            var aTagRxHyhbnvmfnk5oermy = repo.DigitalBanking.LegacyReports.ATagRxHyhbnvmfnk5oermy;

            IList<Ranorex.TrTag>  tablerow = repo.DigitalBanking.LegacyReports.tablerowsInfo.CreateAdapters<Ranorex.TrTag>();
            IList<Ranorex.ATag> header = repo.DigitalBanking.LegacyReports.ATagRxHyhbnvmfnk5oermyInfo.CreateAdapters<Ranorex.ATag>();
            
            var headings = new List<string>(); //saving the header of the table into a list. 
         
            foreach (Ranorex.ATag aitem in header){
            	string headername = aitem.Element.GetAttributeValueText("innertext").ToString();
            	headings.Add(headername);   	    	
            }
            int temp = headings.IndexOf("Report ID");//since the columns can be interchanged, getting the index value of Report ID column
            int i = temp+1; // adding +1 because the first column Action=is spantag
            Report.Info(i.ToString());
            foreach (Ranorex.TrTag item in tablerow){
            	string reportname = item.Element.FindSingle("/td[@childindex='"+i+"']").GetAttributeValueText("innertext").ToString();//getting error here. calling the "i" into the child index
            	Report.Info(reportname);
            }
i am sure that the "i" is same as child index in the spy.

2019-02-04 17_00_30-BottomLineII - Ranorex Studio (Administrator).png
error message
2019-02-04 17_00_30-BottomLineII - Ranorex Studio (Administrator).png (45.69 KiB) Viewed 391 times
please help.

Thank you.
Attachments
table.rxsnp
(439.21 KiB) Downloaded 69 times

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

Re: Read HTML Table Row

Post by odklizec » Tue Feb 05, 2019 8:46 am

Hi,

Try xpath like this:

Code: Select all

//td[@childindex...
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

maamer
Posts: 23
Joined: Fri Nov 30, 2018 6:03 pm

Re: Read HTML Table Row

Post by maamer » Tue Feb 05, 2019 4:17 pm

Hello @odkizec ,
Thank you for the quick reply. the code is working now but it doesnot return the expected innertext of the td tag. i get 28 which is not even there in any of the element properties
2019-02-04 17_00_30-BottomLineII - Ranorex Studio (Administrator).png
2019-02-04 17_00_30-BottomLineII - Ranorex Studio (Administrator).png (20.44 KiB) Viewed 375 times
is there a problem in the HTML parsing in ranorex?. i used chrome so i am ignoring the add on warning.

ahoisl
Certified Professional
Certified Professional
Posts: 181
Joined: Fri Sep 07, 2007 8:16 am

Re: Read HTML Table Row

Post by ahoisl » Tue Feb 05, 2019 10:45 pm

I guess the problem is that you need to specify a relative path. Paths with a leading "/" are always interpreted as absolute paths by Ranorex, so they will search from the root element.

Precede the path with a "." or omit the leading "/" altogether:
string reportname = item.Element.FindSingle("td[@childindex='"+i+"']")...
Regards,
Alex
Ranorex Team

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

Re: Read HTML Table Row

Post by odklizec » Wed Feb 06, 2019 9:10 am

Heh, I'm always forgetting about this "./" trick in code :D
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