Element.ChildCount returns wrong number : Bug Reports

Element.ChildCount returns wrong number

Bug reports and feature requests.

Element.ChildCount returns wrong number

Postby chstnq » Tue May 20, 2008 9:20 am

I want to find out the number of items on a list using the following code:
Code: Select all
..
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
chstnq
 
Posts: 9
Joined: Tue May 20, 2008 8:59 am

Postby Support Team » Tue May 20, 2008 10:21 am

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: Select all
Element[] listItems = listElement.FindChildren(Role.ListItem);
return listItems.Length;
...


Regards,
Alex
Ranorex Support Team
User avatar
Support Team
Site Admin
 
Posts: 4289
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria


Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 0 guests