iLIST Child item properties

Ask general questions here.
IanKnight
Posts: 33
Joined: Thu Feb 21, 2013 12:52 pm

iLIST Child item properties

Post by IanKnight » Thu Jun 04, 2015 1:03 pm

Hi,

We have a little bit of usercode that gets all the items in a list and needs to process them, one by one, by getting the data from the item and processing it.

The code we are using is below and everything works up to the Click.

The next line gets the Children[5] value which is "{Text 'textBlockItemName'} this is the automation ID of the element we are after.

The question is how do I now get the text, or any other, property of that Text control ?

I can't find a way of getting properties for that item, thanks for any help.

Code: Select all

	        var favouritesList = repo.WPF.Place_Order_Form.Select_Order_Items.Favourites_Tab.FavouritesList;
	        int itemCount = 0;
			IList<Ranorex.ListItem> listitems = favouritesList.Items;
			foreach (ListItem listitem in listitems) {
				//If not the header row then remove the favourite
				if (itemCount > 0)
				{
					listitem.Children[1].Click();
					tst_ocs_examination = listitem.Children[5].ToString();

User avatar
subodh4u7
Posts: 68
Joined: Tue Jan 06, 2015 8:26 am

Re: iLIST Child item properties

Post by subodh4u7 » Fri Jun 05, 2015 10:25 am

Using the below code, able to get the text of the element. Similarly you can try to adapt your code. Hope this would help you.

Code: Select all

IList<Ranorex.ListItem> listitems = repo.OrganizerListBox.Items;
			foreach(ListItem listitem in listitems)
			{
				if(repo.OrganizerListBox.Items.Count>0)
				Ranorex.Report.Info(listitem.Children[1].Children[0].ToString());
				Ranorex.Report.Info(listitem.Children[2].Children[0].ToString());
				Ranorex.Report.Info(listitem.Children[3].Children[0].ToString());
				Ranorex.Report.Info(listitem.Children[4].Children[0].ToString());
				
				Ranorex.Report.Info(listitem.Children[5].Children[0].ToString());
				
			}
The output of the above code would be like:
00:20.106 Info User {Text:6/22/1942, F}
00:20.170 Info User {Text:ID: a23364e0-cd9e-445d-8d5b-9f5800fdd1a6}
00:20.230 Info User {Text:Surgery}
00:20.306 Info User {Text:TextBlock}
00:20.361 Info User {Text:6/5/2015, 06:45}
Attachments
Test.jpg
Test.jpg (12.01 KiB) Viewed 1601 times
Regards,
Subodh

IanKnight
Posts: 33
Joined: Thu Feb 21, 2013 12:52 pm

Re: iLIST Child item properties

Post by IanKnight » Fri Jun 05, 2015 6:17 pm

Hi,

Thanks for the reply, unfortunately I had already tried that and it does not work, an Index out of range error is displayed as a failure in the report -

"Index was out of range. Must be non-negative and less than the size of the collection."

IanKnight
Posts: 33
Joined: Thu Feb 21, 2013 12:52 pm

Re: iLIST Child item properties

Post by IanKnight » Wed Jun 10, 2015 11:39 am

Sorry for bumping this to the top, but I have had no luck in resolving it, any other suggestions would be greatly appreciated.

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

Re: iLIST Child item properties

Post by odklizec » Wed Jun 10, 2015 12:37 pm

Hi,

Could you please post Ranorex snapshot both of the list in question and the text element? It would be much easier to help you with better knowledge of application under test.

PS: If I got your problem right, by clicking the list item, you obtain the string {Text 'textBlockItemName'} where 'textBlockItemName' is the ID of element from which you would like to obtain more info? In this case, you will have to parse the whole string {Text 'textBlockItemName'} to obtain just the element ID and then you will have to use "Find" (or similar) method to find the element in question.
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

IanKnight
Posts: 33
Joined: Thu Feb 21, 2013 12:52 pm

Re: iLIST Child item properties

Post by IanKnight » Wed Jun 10, 2015 1:10 pm

I will try and get a snapshot together, but that might not be very helpful in this case.

The issue is that I have an element in the iList, but want to be able to access the properties of that element. It seems a little odd to have the element identified in the iList but then have to go and search the repository again just to get its properties.

** Update - Snapshot attached.
Attachments
ik_favourites_textelement_20150610.rxsnp
(250.34 KiB) Downloaded 52 times
ik_favourites_20150610.rxsnp
(251.33 KiB) Downloaded 46 times

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

Re: iLIST Child item properties

Post by odklizec » Wed Jun 10, 2015 1:58 pm

Hi,

The snapshots definitely helped. Now I see my understanding of your problem was incorrect ;)

Try this code then...
Ranorex.Text getTextElement = listitem.Children[5].Element;
string getTextCaption = getTextElement.Caption;
//eventually
string getTextValue = getTextElement.TextValue;
Hope this helps?
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

IanKnight
Posts: 33
Joined: Thu Feb 21, 2013 12:52 pm

Re: iLIST Child item properties

Post by IanKnight » Wed Jun 10, 2015 2:32 pm

That is great, worked brilliantly.

One other thing, if I wanted to change the .Children[5]. part of the reference to be more specific, i.e. the text element with the AutomationID of "textBlockItemName", can you tell me how you would do that ?

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

Re: iLIST Child item properties

Post by odklizec » Wed Jun 10, 2015 2:58 pm

Good to hear it helped! ;)

As for the other problem, I think you need to use FindChildren method instead of Children[5]. I'm not quite sure about exact code but it could be something like this?
listitem.FindChildren<Ranorex.Text>("textBlockItemName").Element;
//or like this?
listitem.FindChildren(Role.Text, "textBlockItemName").Element;
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