Ranorex

Element.ChildCount returns wrong number

 
Post new topic   Reply to topic    Ranorex Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
chstnq



Joined: 20 May 2008
Posts: 9

PostPosted: Tue May 20, 2008 9:20 am    Post subject: Element.ChildCount returns wrong number
I want to find out the number of items on a list using the following code:
Code: click into code to enlarge

..
int i = 0;
control = form.FindControlId(31);
control.Focus();
controlElement = control.Element;
// Find List
Element listElement = controlElement.FindChild(Role.List);
if (listElement != null)
{
i = listElement.ChildCount;
}
return i;
..


the returned value is wrong and always [expected value] + 1
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 435

PostPosted: Tue May 20, 2008 10:21 am    Post subject:
Actually, that's not a bug. The thing is that not all children of a list element are list items. Usually, there is another child element of role 'Window'. That's why you always get a ChildCount of [number of list items] + 1.

You can use the FindChildren method to search for all items in a list element:
Code: click into code to enlarge
Element[] listItems = listElement.FindChildren(Role.ListItem);
return listItems.Length;
...


Regards,
Alex
Ranorex Support Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Ranorex Forum Index -> Bug Reports All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum