Problem with child window

Jun 19, 2015 at 9:15 AM
Hi,

I'm trying to access a dialog/window which is spawned as a child from the mainform. On other dialogs it works fine, but on this particular dialog the whole UIA framework seems to be freezing. Only after I close the child dialog/window, the UIAFramework continues:

Using the .net4 variant btw.

Working code for "new package dialog":
$global:GUIMainForm = Get-UIAWindow -ProcessName "Automation Machine" -TimeOut 10000 -name "*Automation Machine*"

$GUIMainForm | Get-UiaListItem -Name 'New Package' | Invoke-UIAControlClick
        # Check if new package dialog was opened
        $GUIMainForm | Test-UIAControlState -SearchCriteria @{automationId="AMPackageDialog";controltype="Window";name="Create new Package"} | Should be $true
        $NewPackageDialog = Get-UIAWindow -automationId "AMPackageDialog" -Name "Create new Package"
        # Add button should be disabled when no text has been entered
        $NewPackageDialog | Test-UIAControlState -SearchCriteria @{automationId="buttonOk";controltype="Button";name="Add";IsEnabled=$false}
not working code for "Filter builder dialog"
$global:GUIMainForm = Get-UIAWindow -ProcessName "Automation Machine" -TimeOut 10000 -name "*Automation Machine*"
# clicks the filter button, opens the filter dialog
$GUIMainForm | Get-UiaControl -AutomationId "buttonFilter" | Invoke-uiaControlClick
# The following doesn't work, UIA seems to be hanging indefinately untill I close the opened dialog.

$GUIMainForm | Test-UIAControlState -SearchCriteria @{automationId="FilterExpressionBuilderDialog";controltype="Window";name="Filters: Default action set"}

# This works, get's the dialog and highligts it
$FilterDialog = get-uiawindow -Name "Filters: Default action set"
# Anything I try on the $FilterDialog seems to hang the UIA indefinately, cannot get buttons or anything without haning the UIA framework.
Coordinator
Jun 22, 2015 at 3:04 PM
Hi Henkes,
have you observed this window (the Default action set window) via UIAutomationSpy or, better, more spectacularly showing UIA Verify?
How many controls are situated below this window? On what level (top-level or under your main window) is this window?

Usually, 'freezing' of UIAutomation is just a walk thorough a wrong subtree. Consider the following situation:
-------------------------------your root----------------------
|. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .|
some controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .your child window
|
many controls
|
much more controls

UIAutomation walks through another subtree of controls before visiting the subtree of your interest. This is because the logic is to enumerate top-level items with their subitems from the search root (the Automation Machine window in your case). The first or the second subtree is full of controls and UIAutomation works until it ensures that there is no such element (the .Default action set window).
Good or bad, there is no proof that the algorithm is wrong - if enumerate top-level, the 2nd-level controls and so on, there must be a situation when whis logic will freeze.

Probably, there's another problem. What will be in the output if you run the following:
$FilterDialog | Get-UiaControl | Read-UiaControlName # or Read-UiaControlAutomationId
? Does it return anything or freezes immediately?
Jun 23, 2015 at 7:04 AM
UIAutomationSpy and VisualUIAVerify are able to inspect the "Default action set window" and can see it's controls etc..

It freezes immediately when doing
$FilterDialog | Get-UiaControl | Read-UiaControlName
or
$FilterDialog | Get-UiaControl | Read-UiaControlAutomationId
This,however, does work...
$Expressionpanel = $FilterDialog.NavigateToFirstChild().Highlight()
# Doubleclick first filter 
$listbox = $Expressionpanel.NavigateToFirstChild().NavigateToFirstChild().NavigatetoNextSibling().NavigateToNextSibling().Highlight()
Another strange behaviour i've noticed is with treeview/treeviewitems...
I have a treeview that looks like:

Dashboard
Collections
Layers
Packages

(all rootnodes)

I can get the nodes perfectly by using
$NavigationTree =  $GUIMainForm | Get-UIATree -AutomationId "TreeViewMenu"
$NavigationTree | Get-UiaTreeItem -Name "Dashboard"
$NavigationTree | Get-UiaTreeItem -Name "Collections"
$NavigationTree | Get-UiaTreeItem -Name "Layers"
$NavigationTree | Get-UiaTreeItem -Name "Packages"
But as soon as one of the rootnodes has a childnode,I am no longer able to get treenodes for any of the following rootnodes.
e.g. Dashboard has a childnode, I can get treeitems for Dashboard and it's child, but I can no longer get treeitems for collections, layers or packages
e.g. 2 Collections has a childnode, I can get treeitem for Dashboard,Collections and it's child, but I can no longer get treeitems for layers or packages.

Currenlty i'm working around this by automating bottom to top, first adding all nodes I need to bottom of the tree and then working my way up, but I'm sure i'm going to run into the situation where this workaround will no longer cut it...
Jun 23, 2015 at 7:14 AM
Sorry, forgot to answer some questions:
$FilterDialog is a direct child window from $GUIMainForm, no intermediate controls between $FilterDialog and $GUIMainForm

Filterdialog has 2 panels and 1 titlebar as direct childs.

The folowing does give output and doesn't freeze.
$FilterDialog | Get-UiaControlChildren | Read-UiaControlAutomationId
filterExpressionBuilderControl
panelButtons
TitleBar
Coordinator
Jun 23, 2015 at 8:42 AM
Henkes, are you using UIAutomation 0.87 beta 3?
If so, I'd recommend you to try beta 2 on problematic places. Beta 3 was a release with some polishing done to hide exceptions threw by Microsoft's UI Automation. These exceptions always contains the work 'internal'.

The complaint was that sometimes there is an unhandled exception from Microsoft (something with the 'internal' word), the exception stops the script and I did some work to allow UIAutomation not to be interrupted so often.

If I too polished error handling, you should face such an exception. In this case all that I can do is to better inform the user (and probably repeat the action under the hood).
If there's no such an exception, let's investigate in the issue further.
Jun 23, 2015 at 9:55 AM
Beta2 seems to be giving the same result (freeze). No exception being thrown:
$FilterDialog | Get-UiaControl | Read-UiaControlAutomationId