1. Control classes
You can use the functions of the ListBox or TreeViw class for automating the standard controls.
See the RanorexVS2005Sample2 sample for more details.
You can read and select all items in a ListBox as follows:
Code: click into code to enlarge
itemCount = listBox.ItemCount;
for (int i=0; i < itemCount;i++)
{
text = listBox.GetItemText(i);
Console.WriteLine(" Item[{0}]={1}",i,text);
listBox.SelectedText = text;
}
2. Element class
The Ranorex element approach supports a general way to access every kind of control and control elements. It should also work with custom controls.
The following code reads all items from a listbox:
(This code works in V1.2.0-Beta2 or above)
Code: click into code to enlarge
Element[] listItems = listView.Element.FindChildren(Role.ListItem, null, null, SearchMatchMode.MatchExact);
foreach (Element listItem in listItems)
{
Console.WriteLine("Item={0})", listItem.Name);
}
The following code reads all items from a listbox beginning with "List":
Code: click into code to enlarge
Element[] listItems1 = listView.Element.FindChildren(Role.ListItem,
"List", null, SearchMatchMode.MatchFromStart);
foreach (Element listItem in listItems1)
{
Console.WriteLine("Item={0})", listItem.Name);
}
See the RanorexVS2005Sample3 sample for more details.
Jenö
Ranorex Team |