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
Count of elements within a container
Re: Count of elements within a container
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
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
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Count of elements within a container
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:jainaakash wrote:Q1. Is the above not correct..? Do I need to give sth like below
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
Search for all elements inside the container and then use Count property of the returned list, e.g.: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.
Dim elements As IList(Of Ranorex.Unknown) = containerRow.Find(Of Ranorex.Unknown)("./element") Dim countElements As Integer = elements.CountRegards,
Alex
Ranorex Team
- artur_gadomski
- Posts: 207
- Joined: Mon Jul 19, 2010 6:55 am
- Location: Copenhagen, Denmark
- Contact:
Re: Count of elements within a container
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?
-
- Posts: 48
- Joined: Thu Jun 10, 2010 12:06 pm
Re: Count of elements within a container
Thanks guys, it worked.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Count of elements within a container
That's a perfectly valid wayartur_gadomski wrote:Is this a good way to do that too or am I misusing this method?
I could have used that method in my previous posting instead of the Find method as well...
Regards,
Alex
Ranorex Team
Re: Count of elements within a container
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
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
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Count of elements within a container
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?martinO wrote:counting elements without having to code it
BTW, the code to count elements takes only one line...
Regards,
Alex
Ranorex Team