Treeview Selections

Jan 7, 2013 at 4:04 PM

Background:

I'm in the process of automating some configuration processes, but have run into a snag trying to get items within a treeView control 'checked'.  Can anyone supply a snippet to help me out?

My existing code appears to select the item, but does not actually "check the box"

Get-UIAWindow -name $setupTitle | Get-UIATree | Get-UIATreeItem -Name $featureName | Invoke-UIATreeItemSelectItem -ItemName $featureName 

Thanks

Coordinator
Jan 7, 2013 at 5:31 PM

Hello bohreer,

I created a Windows Forms application with a TreeView control with several nodes, and set its CheckBoxes property to True.

As the SelectItemPattern does nothing except changing the color of a node, the best way is to click to the left from a node:

Get-UIAWindow -pn treeviewtest | Get-UIATreeItem -Name Node0 | Invoke-UIAControlClick -X -10 -Y 3;

The X-coordinate increases from left to right, so that a negative number is what we need to hit outside the node. The Y-coordinate grows from top to bottom, so that we can use 0 or a small positive number to hit into a node. Sometimes people choose too small shift and hit the red border, the module displays by default for the active control...

Coordinator
Jan 8, 2013 at 9:37 AM

With the reorganization of documentation we started recently, we created the Troublrshooting guide section and put the answer to there: http://uiautomation.codeplex.com/wikipage?title=TreeView

Mar 1, 2013 at 12:41 PM
Edited Mar 1, 2013 at 12:51 PM
Is there a way how to get state of the checkbox in treeview? I don't have a problem with checking or unchecking the box, but I need to know the state in some tests and I haven't found a way (items in the tree don't have TogglePattern according to UIVerify).
Mar 6, 2013 at 9:00 AM
Looks like some treeviews in different applications doesn't have TVS_CHECKBOXES style set and in that case UIAutomation doesn't provide toggle pattern for individual items. I haven't found a way around it sadly and only option is to get info from developer what flags they use to handle checkboxes and then via SendMessage get the value.
Coordinator
Mar 7, 2013 at 12:38 PM
There was a thought, months ago, to add image recognition mechanism (based on OpenCV or another library). When searching of a small area, it should work fast. I mean that code should be something like:
function Get-TreeItemCheckedState
{
param($Name)

[void]($treeItem = Get-UIATreeItem -Name $Name);

if ((Search-UIAImageMatch -InputObject $treeItem -X -30 -Y 5 -Image 'checked.bmp')) return $true;
}
I think, I can implement this during this week.
Mar 7, 2013 at 2:28 PM
That would be fantastic having some image recognition support in these cmdlets.