ListView and TreeView Controls
These methods use Windows Automation operate on Automation Elements with the property ControlType.List or ControlType.TreeItem. They may behave differently to similar methods on the WinDriver Control object, which only operate on SysTreeView32 and SysListView32 window classes
ListView
Method | Description |
---|---|
Return the number of items in the List |
|
Return the location coordinates of the item with the given index number or name |
TreeView
Method | Description |
---|---|
Return the number of visible items in the Tree |
|
Return the location coordinates of the item with the given name |
|
Return the rectangle enclosing the item |
|
Return the location of the item |
|
Set the item to the selected state |
|
Get the text of the item for the given index number |
Example
AutomationControl runWindow = FindTopAutomationWindow("Two ListBox DragDrop Demo");
IList<AutomationControl> lists = runWindow.FindControls(ControlType.List); //finds all list controls by control type
runWindow.ToControl().ShowWindow(); //makes sure that window is visible
runWindow.SetForegroundWindow(); //makes sure that window is in foreground and active
foreach (AutomationControl list in lists) //gets the number of items each list holding
{
int n = list.GetListItemCount();
WriteMessage("List items:"+n);
}
AutomationControl window = FindTopAutomationWindow("Demo App (multiple selection treeview");
window.ToControl().ShowWindow(ShowWindowCodes.SW_MAXIMIZE); //maximizes window if minimized
window.SetForegroundWindow();
AutomationControl tree = window.FindControl(ControlType.Tree); //gets tree control
tree.ExpandTreeItem(tree.GetTreeItemText(0)); //expands tree
Point p = tree.GetTreeItemLocation(tree.GetTreeItemText(0)); //close tree. This method can be used for both, to expand and to close
Mouse.DoubleLeftClick(p);