Page 1 of 1

Element.ChildCount returns wrong number

Posted: Tue May 20, 2008 8:20 am
by chstnq
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

Posted: Tue May 20, 2008 9:21 am
by Support Team
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