How to get Popup window?

Oct 31, 2008 at 6:18 PM
I am trying to automate one WPF application that uses a popup to present several "Menu items" to the user.

However the "menu" is not a standard one but one created by following XAML definition:

<Popup Name="popupMenu" Closed="popupMenu_Closed" IsOpen="False" ClipToBounds="False" PopupAnimation="Fade" >
    <Border BorderThickness="1,1,1,1" BorderBrush="Gray" CornerRadius="5"  >
        <StackPanel Name="popupMenuStackPanel" Orientation="Horizontal" Background="WhiteSmoke" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <Button Style="{StaticResource FlatButton}">
                <DockPanel Margin="5,0,5,5">
                    <Ellipse DockPanel.Dock="Left" Margin="5" Width="20" Height="20" Stroke="Black" Fill="White"/>
                    <TextBlock DockPanel.Dock="Top" Foreground="Black">MenuItem Name</TextBlock>
                    <TextBlock DockPanel.Dock="Top" FontSize="10">MenuItem Description</TextBlock>
                </DockPanel>
            </Button>
...
        </StackPanel>
    </Border>
</Popup>

The problem now is that I do not know how to get hold of this Popup window and/or its items.
The Window.PopupMenu expects a path of text that is visible to the user, but it seems that no Popup can even be created (in WPFWindow the Popup method is not able to create a Window instance - it just gets null).
The popup opens using a standard mouse click on a button in the UI not the usual right-click.
In MSDN I read that popups are located in a different visual tree, which might be another cause of the problem.

When I use UISpy, the UI item can be found, but the Automation-ID is "". The same applies to the window (name and autom.ID are "").
Using another tool I found ("Snoop") a much more detailed tree is shown which also shows the used Automation-IDs, but the tree is not located as in UISpy below the Application's main window but starts with an unnamed "PopupRoot" element.

This seems to be quite strange.

Any idea what I could do?
Coordinator
Nov 9, 2008 at 4:46 AM
Is it possible for you to provide me the complete code sample?
Nov 10, 2008 at 2:52 PM
Edited Nov 10, 2008 at 2:54 PM
Unfortunately the application is a commercial one. Our company's guidelines forbid publication of any source code without NDA.
Therefore I tweaked the original and following snippet not to contain any real reference. I marked the changes here using "<..>".
The <MenuItem Description> contains a linebreak, just in case it might be important.

As the application is developed by another team I do not have direct access to the project anyway.
Would you need the C# or XAML source code?

Anyway here is what UISpy could detect. Maybe this also helps to find the cause of the problem.

Control View:

- "pane" ""(Desktop Window)
  - "window" ""
    - "button" ""
      - "text" "<MenuItem Name>"
      - "text" "<MenuItem Description>"
    .. (other buttons)
  .. (other panes and windows)
  - "window" "<main application window>"
  .. (other panes and windows)

Properties:

window "":

AutomationElement
  General Accessibility
    AccessKey:    ""
    AcceleratorKey:    ""
    IsKeyboardFocusable:    "True"
    LabeledBy:    "(null)"
    HelpText:    ""

  State
    IsEnabled:    "True"
    HasKeyboardFocus:    "False"

  Identification
    ClassName:    "Popup"
    ControlType:    "ControlType.Window"
    Culture:    "(null)"
    AutomationId:    ""
    LocalizedControlType:    "window"
    Name:    ""
    ProcessId:    "2200 (<our application>)"
    RuntimeId:    "42 655870"
    IsPassword:    "False"
    IsControlElement:    "True"
    IsContentElement:    "True"

  Visibility
    BoundingRectangle:    "(80, 88, 437, 48)"
    ClickablePoint:    "298.5,112"
    IsOffscreen:    "False"

ControlPatterns

button "":

AutomationElement
  General Accessibility
    AccessKey:    ""
    AcceleratorKey:    ""
    IsKeyboardFocusable:    "True"
    LabeledBy:    "(null)"
    HelpText:    ""

  State
    IsEnabled:    "True"
    HasKeyboardFocus:    "False"

  Identification
    ClassName:    "Button"
    ControlType:    "ControlType.Button"
    Culture:    "(null)"
    AutomationId:    "button<MenuItem Name>"
    LocalizedControlType:    "button"
    Name:    ""
    ProcessId:    "2200 (<our application>)"
    RuntimeId:    "7 2200 15644031"
    IsPassword:    "False"
    IsControlElement:    "True"
    IsContentElement:    "True"

  Visibility
    BoundingRectangle:    "(81, 89, 71, 46)"
    ClickablePoint:    "116.5,112"
    IsOffscreen:    "False"

ControlPatterns
  Invoke

text "<MenuItem Description>":
AutomationElement
  General Accessibility
    AccessKey:    ""
    AcceleratorKey:    ""
    IsKeyboardFocusable:    "False"
    LabeledBy:    "(null)"
    HelpText:    ""

  State
    IsEnabled:    "True"
    HasKeyboardFocus:    "False"

  Identification
    ClassName:    "TextBlock"
    ControlType:    "ControlType.Text"
    Culture:    "(null)"
    AutomationId:    ""
    LocalizedControlType:    "text"
    Name:    "<MenuItem Description>"
    ProcessId:    "2200 (<our application>)"
    RuntimeId:    "7 2200 53934008"
    IsPassword:    "False"
    IsControlElement:    "True"
    IsContentElement:    "True"

  Visibility
    BoundingRectangle:    "(88, 104, 57, 24)"
    ClickablePoint:    "116.5,116"
    IsOffscreen:    "False"

ControlPatterns

Coordinator
Nov 12, 2008 at 6:37 PM
ok then lets do this.
in your test perform the action to get the popup menu. do a Desktop.Instance.LogStructure() and send me the output which comes out on the console. Please attach it to a file so that I can see the indentations in the output. you would have configure log4net for it. How to, is on the website.
Do not have too many other windows open while this is happening.
Sep 23, 2009 at 4:11 AM

I had a WPF popup with a similar structure.  My popup didn't have a button inside.

window.LogStructure() produced the exact same output as UISpy.

I was able to get my menu through the following:

Menu menuItem = window.Get<Menu>(SearchConditions.ByText("My Menu Item"))