Page 1 of 1

Count List Items

Posted: Tue Oct 18, 2016 4:23 pm
by roxter
Hello!
I need to validate dynamic list output.What I would like to do is to count all Div 'ng-scope' items in a DOM (please see attached screenshot).
The 'ng-scope' items represent search results in a table I would like to validate.
How can this be done in C# user code?

Re: Count List Items

Posted: Tue Oct 18, 2016 5:50 pm
by Vaughan.Douglas
Something along the lines of this should get you what you need:

Code: Select all

            Validate.AreEqual(Host.Local.Find<DivTag>("descendant::div[@class='ng-scope']", 30000).Count, myExpected,
                "The actual count was {0}, the expected count was {1}");
myExpected is a variable containing the expected count

Code: Select all

Host.Local.Find<DivTag>("descendant::div[@class='ng-scope']", 30000) 
will get you a collection (iList) of DivTag objects.

I would have to recommend finding a repo object to use the find method on rather than using Host.Local just to scale back the amount of searching Ranorex is going to have to do.

also I just assumed "ng-scope" was the class attribute, you'll need to update the snippet if that is not the case.