Count of elements within a container : Automation API

Count of elements within a container

Class library usage, coding and language questions.

Count of elements within a container

Postby jainaakash » Wed Jul 21, 2010 2: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[i]/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[i]) and then try to find text.


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

Re: Count of elements within a container

Postby sdaly » Wed Jul 21, 2010 2: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
sdaly
 
Posts: 213
Joined: Mon May 10, 2010 12:04 pm
Location: Dundee, Scotland

Re: Count of elements within a container

Postby Support Team » Wed Jul 21, 2010 3: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
User avatar
Support Team
Site Admin
 
Posts: 4840
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Count of elements within a container

Postby artur_gadomski » Thu Jul 22, 2010 7: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?
User avatar
artur_gadomski
 
Posts: 125
Joined: Mon Jul 19, 2010 7:55 am
Location: Copenhagen, Denmark

Re: Count of elements within a container

Postby jainaakash » Thu Jul 22, 2010 9:08 am

Thanks guys, it worked.
jainaakash
 
Posts: 48
Joined: Thu Jun 10, 2010 1:06 pm

Re: Count of elements within a container

Postby Support Team » Thu Jul 22, 2010 11: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
User avatar
Support Team
Site Admin
 
Posts: 4840
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Count of elements within a container

Postby martinO » Thu Apr 07, 2011 5: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
martinO
 
Posts: 4
Joined: Tue Dec 14, 2010 4:51 pm

Re: Count of elements within a container

Postby Support Team » Thu Apr 07, 2011 5: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
User avatar
Support Team
Site Admin
 
Posts: 4840
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests