| View previous topic :: View next topic |
| Author |
Message |
chstnq
Joined: 20 May 2008 Posts: 9
|
Posted: 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 |
|
 |
Support Team Site Admin
Joined: 07 Jul 2006 Posts: 435
|
Posted: 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 |
|
 |
|