How to handle PopupMenu WinForm .Net 3.0

Nov 24, 2008 at 12:24 PM
Hello,

Assuming I have a blank WinForm and a contextStripMenu containing two items.

mnuPopupMenu [PopupMenu]
    mnuMenu1 [Menu1]
    mnuMenu2 [Menu2]

Text property is showed between []

In my test class I have an handler to the WinForm and I would like to click on Menu2 for instance.
How could I do? I can't figure out how to have an handler on Menu2 and then to call the Click method for example.

This is my test

            window.RightClick();

            Assert.IsTrue(window.HasPopup());

            Thread.Sleep(100);

            PopUpMenu popup=null;

            PrimaryUIItemFactory factory = new PrimaryUIItemFactory(new AutomationElementFinder(window.AutomationElement));

            Assert.IsTrue(factory.TryGetPopupMenu(window, out popup));
           
            Console.WriteLine("WINDOW");

            window.LogStructure();

            Console.WriteLine("MENU");

            popup.LogStructure();

--------------------------------------------------------------------------------------
If I try to use popup.Item("Menu2") I get an exception.

This is the output

WINDOW
[2008-11-24 14:15:47,777][INFO ] AutomationId: Form1
ControlType: ControlType.Window
Name: Form1
HelpText:
Bounding rectangle: 66;87;300;300
ClassName: WindowsForms10.Window.8.app.0.378734a
IsOffScreen: False

    AutomationId:
    ControlType: ControlType.Menu
    Name: DropDown
    HelpText:
    Bounding rectangle: 216;237;118;48
    ClassName: WindowsForms10.Window.808.app.0.378734a
    IsOffScreen: False

    AutomationId: TitleBar
    ControlType: ControlType.TitleBar
    Name: Form1
    HelpText:
    Bounding rectangle: 70;91;292;26
    ClassName:
    IsOffScreen: False

        AutomationId: Form1
        ControlType: ControlType.MenuBar
        Name: System Menu Bar
        HelpText:
        Bounding rectangle: 70;91;18;25
        ClassName:
        IsOffScreen: False

            AutomationId: Item 1
            ControlType: ControlType.MenuItem
            Name: System
            HelpText:
            Bounding rectangle: 70;91;18;25
            ClassName:
            IsOffScreen: False

        AutomationId: Minimize
        ControlType: ControlType.Button
        Name: Minimize
        HelpText:
        Bounding rectangle: 290;91;24;24
        ClassName:
        IsOffScreen: False

        AutomationId: Maximize
        ControlType: ControlType.Button
        Name: Maximize
        HelpText:
        Bounding rectangle: 314;91;24;24
        ClassName:
        IsOffScreen: False

        AutomationId: Close
        ControlType: ControlType.Button
        Name: Close
        HelpText:
        Bounding rectangle: 338;91;24;24
        ClassName:
        IsOffScreen: False

MENU
[2008-11-24 14:15:47,807][INFO ] AutomationId:
ControlType: ControlType.Menu
Name: DropDown
HelpText:
Bounding rectangle: 216;237;118;48
ClassName: WindowsForms10.Window.808.app.0.378734a
IsOffScreen: False
--------------------------------------------------------------------------------------

I can't figure out why I have DropDown as name.
Could you please advice? Many thanks

Coordinator
Nov 25, 2008 at 2:48 AM
Doesn't seem to show anything present inside the popup automation element?
Can you use UISpy and mouse tracking to see what else it shows?
Nov 25, 2008 at 8:37 AM

I only have "menu" "DropDown" in UISpy treeview and in the properties panel.
I can't see the children items.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This is my log in hovering mode
[There is a label displaying which item has been clicked]

Property Change Event
Time Stamp : 25.11.2008 09:58:24
Element : "menu" "DropDown"
Property : AutomationElementIdentifiers.BoundingRectangleProperty
New Value : 324;393;118;48
Old Value : Empty

Structure Change Event
Time Stamp : 25.11.2008 09:58:24
Element : "menu" "DropDown"
Structure Change Type : ChildAdded
Runtime ID : 42 2753264

Structure Change Event
Time Stamp : 25.11.2008 09:58:24
Element : "menu" "DropDown"
Structure Change Type : ChildAdded
Runtime ID : 42 2753264

Automation Event
Time Stamp : 25.11.2008 09:58:24Element:"menu" "DropDown"
Name : AutomationElementIdentifiers.MenuOpenedEvent

Property Change Event
Time Stamp : 25.11.2008 09:58:24
Element : "text" "Menu 2 clicked"
Property : AutomationElementIdentifiers.NameProperty
New Value : Menu 2 clicked
Old Value : null

AutomationElementIdentifiers.MenuClosedEvent event occurred with a null object
Time Stamp : 25.11.2008 09:58:24

Property Change Event
Time Stamp : 25.11.2008 09:58:24
Element : "text" "Menu 2 clicked"
Property : AutomationElementIdentifiers.IsOffscreenProperty
New Value : False
Old Value : null

Property Change Event
Time Stamp : 25.11.2008 09:58:24
Element : "text" "Menu 2 clicked"
Property : AutomationElementIdentifiers.IsOffscreenProperty
New Value : False
Old Value : null

Property Change Event
Time Stamp : 25.11.2008 09:58:24
Element : "text" "Menu 2 clicked"
Property : AutomationElementIdentifiers.BoundingRectangleProperty
New Value : 183;248;80;13
Old Value : Empty

AutomationElementIdentifiers.MenuClosedEvent event occurred with a null object
Time Stamp : 25.11.2008 09:58:29

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This is what i get in Focus tracking mode

Focus Change Event
Time Stamp : 25.11.2008 10:34:35
Element : "window" "Form1"
Object ID : -4
Child ID : 0

Exception
Time Stamp : 25.11.2008 10:34
Element : Element details not available.
Name : TreeValidationException
Message : UI Automation tree navigation is broken. The parent of one of the descendants exist but the descendant is not the child of the parent
Stack Trace :    at UISpy.Base.Tree.BuildTree(AutomationElement element)
   at UISpy.Base.Tree.BuildTreeAndRelatedTrees(AutomationElement element)

Focus Change Event
Time Stamp : 25.11.2008 10:34:37
Element : "menu item" "Menu1"
Object ID : -4
Child ID : 1

Dec 1, 2008 at 10:49 AM
I have looked at white source code and I assume the problem I'm encounterning is due to AutomationElement.
Actually there is no children foundable using the find method for ContextMenu.
Are you aware of this kind of bug?
Do you know a way to hack this?
Coordinator
Dec 5, 2008 at 2:38 PM
there is one more thing we can try.
Can you please do Desktop.Instance.LogStructure() and send me the console output. (do this exactly when the popup is displayed) Please attach this in a file so that I can see the indentations.
Warning: Please close other windows on desktop which you dont need, as that might increase the size of the output as well might take longer dump.