iterate through h2tag elements and get innertext

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

iterate through h2tag elements and get innertext

Post by maamer » Mon Dec 03, 2018 5:25 pm

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);

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.
thank you
You do not have the required permissions to view the files attached to this post.

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

Re: iterate through h2tag elements and get innertext

Post by maamer » Mon Dec 03, 2018 6:35 pm

update:
i modified the code:

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

names.Add(tagh2.Element.GetAttributeValueText("innertext").ToString());
Report.Info("account name is: "+names.ToString());}

and getting this:
00:06.950 Info User

starting test
00:07.237 Info User

account name is: System.Collections.Generic.List`1[System.String]
00:07.240 Info User

account name is: System.Collections.Generic.List`1[System.String]
00:07.242 Info User

account name is: System.Collections.Generic.List`1[System.String]
00:07.245 Info User

account name is: System.Collections.Generic.List`1[System.String]
00:07.248 Info User

account name is: System.Collections.Generic.List`1[System.String]
00:07.250 Info User

account name is: System.Collections.Generic.List`1[System.String]
00:07.252 Info User

account name is: System.Collections.Generic.List`1[System.String]
00:07.255 Info User

account name is: System.Collections.Generic.List`1[System.String]
00:07.256 Info User

account name is: System.Collections.Generic.List`1[System.String]
00:07.259 Info User

account name is: System.Collections.Generic.List`1[System.String]
00:07.261 Info User

account name is: System.Collections.Generic.List`1[System.String]

hot to display the name of the element's innertext here?

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

Re: iterate through h2tag elements and get innertext

Post by odklizec » Tue Dec 04, 2018 8:35 am

Hi,

At first, the repo item xpath should look like this:
/dom[@domain='6012-sbx.btbanking.com']//div[#'dashboard-region-430']//div//ul/li//h2[@visible='true']
Above xpath returns list of visible H2 elements, form which you can easily obtain innertext attribute from each H2 element.

The code you are looking for could be something like this...

Code: Select all

		public void GetInnerText(RepoItemInfo ElementName)
		{
			// Create a list of H2Tag adapters, using the "Info" object
			IList<Ranorex.H2tag> h2List = ElementName.CreateAdapters<Ranorex.H2Tag>();
			// Get InnerText from each H2 tag in the list
			foreach (Ranorex.H2Tag h2Item in h2List)
			{
				string h2Text = h2Item.InnerText.ToString();
				Report.Log(ReportLevel.Info, h2Text);
			}
		}
Simply create a new UserCode with parameter pointing to the repo element with above xpath. The code will create list of H2Tags an then get the innertext value from each item in the list. Hope this helps?
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: iterate through h2tag elements and get innertext

Post by maamer » Tue Dec 04, 2018 3:24 pm

thank you sir, that worked!!! :)