Count of elements within a container

Class library usage, coding and language questions.
jainaakash
Posts: 48
Joined: Thu Jun 10, 2010 12:06 pm

Count of elements within a container

Post by jainaakash » Wed Jul 21, 2010 1:33 pm

Hi Team,

I need to get the count of elements within a container. Please let me know how can I do that.

In the following RxPath,
-------
/container[@automationid='Group_0']/element[6]/container[@automationid='ID']/text[@name='999']
-------
I know the first container (automationid=Group_0). Now I want to find a text which reside in at the above path but we dont know at which element id. I tried the following but it didn't work:

-----
Dim containerRow As Ranorex.Container = tblGrid.FindSingle (Of Ranorex.Container)("./Container[@automationid='Group_0]")
Dim idCell As Ranorex.Text = containerRow.FindSingle(of Ranorex.Text) ("./element/container[@automationid='ID']/text[@name='999']")
ttidCell.MoveTo
ttidCell.DoubleClick
-----

Q1. Is the above not correct..? Do I need to give sth like below
--
Dim idCell As Ranorex.Text = containerRow.FindSingle(of Ranorex.Text) ("./element[]/container[@automationid='ID']/text[@name='999']")
or
' i as counter
Dim idCell As Ranorex.Text = containerRow.FindSingle(of Ranorex.Text) ("./element/container[@automationid='ID']/text[@name='999']")
--

Q2 How do I get the count for number of elements in the container so that I can loop in through and provide element details (like element) and then try to find text.


Thanks

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: Count of elements within a container

Post by sdaly » Wed Jul 21, 2010 1:54 pm

To loop through items, this is one way of doing it -

Dim lstitems As List(Of Ranorex.Core.Element) = host.Local.Find("/desktop[@processname='explorer']/container/list/listitem")
msgbox(lstitems.count.tostring)
For Each item As Ranorex.ListItem In lstitems
item.MoveTo
Next


Hope this helps!
Scott

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Count of elements within a container

Post by Support Team » Wed Jul 21, 2010 2:04 pm

jainaakash wrote:Q1. Is the above not correct..? Do I need to give sth like below
Yes, the above code should be correct. If you omit the indexer ("element[6]" -> "element"), Ranorex tries to find the remaining part of the RxPath in every of the elements inside the container. So, the following code should be working:
Dim containerRow As Ranorex.Container = tblGrid.FindSingle (Of Ranorex.Container)("./Container[@automationid='Group_0]")
Dim idCell As Ranorex.Text = containerRow.FindSingle(of Ranorex.Text) ("./element/container[@automationid='ID']/text[@name='999']")
idCell.MoveTo
idCell.DoubleClick
jainaakash wrote:Q2 How do I get the count for number of elements in the container so that I can loop in through and provide element details (like element) and then try to find text.
Search for all elements inside the container and then use Count property of the returned list, e.g.:
Dim elements As IList(Of Ranorex.Unknown) = containerRow.Find(Of Ranorex.Unknown)("./element")
Dim countElements As Integer = elements.Count
Regards,
Alex
Ranorex Team
.
Image

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Count of elements within a container

Post by artur_gadomski » Thu Jul 22, 2010 6:41 am

I find all the elemts by calling FindChildren method
IList<ComboBox> comboBoxes = repo.SomeForm.SomeOtherForm.FindChildren<ComboBox>();
Is this a good way to do that too or am I misusing this method?

jainaakash
Posts: 48
Joined: Thu Jun 10, 2010 12:06 pm

Re: Count of elements within a container

Post by jainaakash » Thu Jul 22, 2010 8:08 am

Thanks guys, it worked.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Count of elements within a container

Post by Support Team » Thu Jul 22, 2010 10:19 am

artur_gadomski wrote:Is this a good way to do that too or am I misusing this method?
That's a perfectly valid way :-)
I could have used that method in my previous posting instead of the Find method as well...

Regards,
Alex
Ranorex Team
.
Image

martinO
Posts: 4
Joined: Tue Dec 14, 2010 3:51 pm

Re: Count of elements within a container

Post by martinO » Thu Apr 07, 2011 4:22 pm

Hi Support Team

We would like to record/write our tests within Ranorex Studio without coding. Is there any way with Ranorex 3 to realize the discussed functionality of counting elements without having to code it? What is the easiest way to write a test that includes counting elements?

Thanks for your reply,
Fredi

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Count of elements within a container

Post by Support Team » Thu Apr 07, 2011 4:57 pm

martinO wrote:counting elements without having to code it
No, the recorder does not provide that functionality. However, even if it would, after you counted the elements, what would you want to do with that number then from the recorder? So what is the use case?

BTW, the code to count elements takes only one line...

Regards,
Alex
Ranorex Team
.
Image