Page 1 of 1

Read HTML Table Row

Posted: Mon Feb 04, 2019 11:01 pm
by maamer
Hello All,

I am Trying to read an HTML table. the columns in this table can be interchanged.
aVwdI-1.png
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
please help.

Thank you.

Re: Read HTML Table Row

Posted: Tue Feb 05, 2019 8:46 am
by odklizec
Hi,

Try xpath like this:

Code: Select all

//td[@childindex...

Re: Read HTML Table Row

Posted: Tue Feb 05, 2019 4:17 pm
by maamer
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
is there a problem in the HTML parsing in ranorex?. i used chrome so i am ignoring the add on warning.

Re: Read HTML Table Row

Posted: Tue Feb 05, 2019 10:45 pm
by ahoisl
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

Re: Read HTML Table Row

Posted: Wed Feb 06, 2019 9:10 am
by odklizec
Heh, I'm always forgetting about this "./" trick in code :D