iterate through h2tag elements and get innertext!

Class library usage, coding and language questions.
tinekastil2
Posts: 3
Joined: Mon Jun 22, 2020 5:20 pm

iterate through h2tag elements and get innertext!

Post by tinekastil2 » Tue Feb 16, 2021 7:42 am

hello ,
iam trying to iterate between the h2tag elements and store the innertext in a list and display the list in the report. iam getting the errors
my code:
var repo = BottomLineIIRepository.Instance;
var acclist = repo.DigitalBanking.Accounts.acclist;
Report.Log(ReportLevel.Info,"starting test");

IList<Ranorex.H2Tag> accnamelist = repo.DigitalBanking.Accounts.acclistInfo.CreateAdapters<Ranorex.H2Tag>();
List<Ranorex.H2Tag> names = new List<H2Tag> {};
foreach (Ranorex.H2Tag tagh2 in accnamelist)

names.Add(tagh2.Element.GetAttributeValueText("innertext").ToString());
Report.Info("account name is: "+names);
https://essaywriter.fun/
the error is:
Parsing RxPath 'Non Profit CD - 394518999' failed.
line 1:15 no viable alternative at character ' '
line 1:0 no viable alternative at input 'Non'
Show/Hide Stacktrace at Ranorex.Core.RxPath..ctor(String path) at Ranorex.Core.Element.FromPath(String path) at Ranorex.H2Tag.op_Implicit(String path) at BottomLineII.Small_Business.Accounts.accountvalidation.Ranorex.Core.Testing.ITestModule.Run() in c:\Dev\Git\Online\BottomLineII\BottomLineII\Small Business\Accounts\accountvalidation.cs:line 59 at Ranorex.Core.Testing.TestModuleLeaf.RunInternal(DataContext parentDataContext, Int32 iteration, Int32 iterationCount, Boolean skipIteration)

please help.

manish
Posts: 51
Joined: Fri Aug 10, 2018 12:46 pm

Re: iterate through h2tag elements and get innertext!

Post by manish » Wed Feb 24, 2021 10:31 am

Hi,

Could you try using the Find to get all H2Tags from your repo element.

Something like this

Code: Select all

			var repo = BottomLineIIRepository.Instance;
			var acclist = repo.DigitalBanking.Accounts.acclist;
			Report.Log(ReportLevel.Info,"starting test");

			IList<Ranorex.H2Tag> accnamelist = repo.DigitalBanking.Accounts.acclistInfo.Find<H2Tag>("//h2tag");
			List<Ranorex.H2Tag> names = new List<H2Tag> {};
			foreach (var tagh2 in accnamelist){
				names.Add(tagh2.Element.GetAttributeValueText("innertext").ToString());
				Report.Info("account name is: "+names);
			}

This will give all the J2tags present below acclist . If you wish to find only the immediate children then use FindChildren method.

Thanks
Manish