Page 1 of 1

loop through UI elements

Posted: Fri Nov 30, 2018 10:50 pm
by maamer
hello,
iam trying to loop through 11 Li elements to extract the inner text of h2 and h3 tags. iam getting errors below. please help

this is my sample code
void ITestModule.Run()
{
Mouse.DefaultMoveTime = 300;
Keyboard.DefaultKeyPressTime = 100;
Delay.SpeedFactor = 1.0;

var repo = BottomLineIIRepository.Instance;
var accname = repo.DigitalBanking.Accounts.accname;
var checkingacccont = repo.DigitalBanking.Accounts.checkingacccont;
var cardslist = repo.DigitalBanking.Accounts.cardslist;
//string[] list= new string[] {(List)cardslist};
IList mylist = accname.InnerText.ToList();
string acc_name = "";
foreach (var accname in accname)
acc_name=accname.GetAttributeValueText();

the error is:
A local variable named 'accname' cannot be declared in this scope because it would give a different meaning to 'accname', which is already used in a 'parent or current' scope to denote something else (CS0136) - C:\Dev\Git\Online\BottomLineII\BottomLineII\Small Business\Accounts\accountvalidation.cs:58,26
foreach statement cannot operate on variables of type 'Ranorex.H2Tag' because 'Ranorex.H2Tag' does not contain a public definition for 'GetEnumerator' (CS1579) - C:\Dev\Git\Online\BottomLineII\BottomLineII\Small Business\Accounts\accountvalidation.cs:58,13

iam attaching scapshot of the elements iam trying to loop.
li.png

Re: loop through UI elements

Posted: Sat Dec 01, 2018 11:44 am
by odklizec
Hi,

Could you please upload a Ranorex snapshot showing the list of li elements? Screenshot is not very useful here. Also, I would suggest you to check this Ranorex code sample, describing how to create a list of adapters from repo element...
https://www.ranorex.com/#Createalistofa ... oryelement

Re: loop through UI elements

Posted: Sun Dec 02, 2018 9:33 pm
by maamer
those are the Li tags in the spy screenshot. each Li tag has div/div/h2 and h3 tags . i want to write a foreach loop to get the innertext of the h2 and h3 tags here. i do not have any other screenshot

Re: loop through UI elements

Posted: Sun Dec 02, 2018 10:54 pm
by odklizec
Hi,

I’m not asking for screenshot but snapshot! Please learn how to create one here...
https://www.ranorex.com/help/latest/ran ... hot-files/
Anyway, the link with code examples I posted before should lead the way.

Re: loop through UI elements

Posted: Mon Dec 03, 2018 3:33 pm
by maamer
hello,
thank you for helping me. iam attaching the rxsnp. i am not able to follow the article on creating the list of adapters . i didnot understand how to implement in my project. please help.
thank you

Re: loop through UI elements

Posted: Mon Dec 03, 2018 4:43 pm
by maamer
i tried to do this
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.InnerText);
Report.Info("account name is: "+names);
getting this error in report:

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 58 at Ranorex.Core.Testing.TestModuleLeaf.RunInternal(DataContext parentDataContext, Int32 iteration, Int32 iterationCount, Boolean skipIteration)

Re: loop through UI elements

Posted: Tue Dec 04, 2018 8:37 am
by odklizec
Hi,

I answered the problem in your other post here:
viewtopic.php?f=13&t=13028&p=51724