loop through UI elements

Best practices, code snippets for common functionality, examples, and guidelines.
maamer
Posts: 23
Joined: Fri Nov 30, 2018 6:03 pm

loop through UI elements

Post by maamer » Fri Nov 30, 2018 10:50 pm

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

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

Re: loop through UI elements

Post by odklizec » Sat Dec 01, 2018 11:44 am

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
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: loop through UI elements

Post by maamer » Sun Dec 02, 2018 9:33 pm

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

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

Re: loop through UI elements

Post by odklizec » Sun Dec 02, 2018 10:54 pm

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.
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: loop through UI elements

Post by maamer » Mon Dec 03, 2018 3:33 pm

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
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: loop through UI elements

Post by maamer » Mon Dec 03, 2018 4:43 pm

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)

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

Re: loop through UI elements

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

Hi,

I answered the problem in your other post here:
viewtopic.php?f=13&t=13028&p=51724
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