How to find controls added at runtime

Feb 20, 2009 at 2:54 PM
I have a application where the menus may vary depending on the user configuration.

The menu structure is on a table that is loaded every time the user enters in the application.

When I use UISpy to find those elements I can't see them, even when I try to use White framework to find those elements I can only reach the ones that where not added on runtime.

Thanks for any question that can leave to solve this problem.
Coordinator
Feb 28, 2009 at 3:36 PM
you would need to get a new object for MenuBar from window in order to do this. let me know if even this doesnt work.
Mar 2, 2009 at 10:11 PM

Hello!!

I send you my window.LogStructure(), that is what White can see at the moment I'm on this window, but when I use snoop he can see more. I'll try to explain:

You can see in the LogStructure that I send you a element that give by the name Workspace_ProcessMenu, that white can see but in the same node there is another element that white can't see (I Think) and snoop does. Bellow I try to send you the tree that snoop see:

Workspace_ProcessMenu (Button) - This item White can reach

Shell_Workspace_ProcessMenu (That I think is a control) This item White can't reach
   Grid (Grid control)
      ScrollViewer (ScrollViewer control)
         Grid (Grid control)
            Corner (Rectangle)
         PART_ScrollContentPresenter (Custom control)
             Shell_ProcessCategoryMenu (Items Control)
                 Border
                     ItemsPresenter
                         StackPanel
                             GroupItem
                                  Expander
                                      Grid
                                          Border
                                              ContentPresenter
                                                  ItemsPresenter
                                                      WrapPanel
                                                         ContentPresenter
                                                            Grid
                                                                ItemsControl
                                                                   Border
                                                                      ItemsPresenter
                                                                         StackPanel
                                                                            ContentPresenter
                                                                               Button
                                                                                  TextBlock - This is the item I'm trying to reach.





AutomationId:
ControlType: ControlType.Window
Name: Primavera Express
HelpText:
Bounding rectangle: -32000;-32000;160;25
ClassName: Window
IsOffScreen: False

    AutomationId: TitleBar
    ControlType: ControlType.TitleBar
    Name: Primavera Express
    HelpText:
    Bounding rectangle: -31992;-31992;144;20
    ClassName:
    IsOffScreen: True

        AutomationId: SystemMenuBar
        ControlType: ControlType.MenuBar
        Name: System Menu Bar
        HelpText:
        Bounding rectangle: -31992;-31992;19;19
        ClassName:
        IsOffScreen: True

            AutomationId: Item 1
            ControlType: ControlType.MenuItem
            Name: System
            HelpText:
            Bounding rectangle: -31992;-31992;19;19
            ClassName:
            IsOffScreen: True

        AutomationId: Restore
        ControlType: ControlType.Button
        Name: Restore
        HelpText:
        Bounding rectangle: -31941;-31999;26;18
        ClassName:
        IsOffScreen: True

        AutomationId: Maximize
        ControlType: ControlType.Button
        Name: Maximize
        HelpText:
        Bounding rectangle: -31915;-31999;25;18
        ClassName:
        IsOffScreen: True

        AutomationId: Close
        ControlType: ControlType.Button
        Name: Close
        HelpText:
        Bounding rectangle: -31890;-31999;44;18
        ClassName:
        IsOffScreen: True

    AutomationId: Shell_Header
    ControlType: ControlType.Custom
    Name:
    HelpText:
    Bounding rectangle: -32000;-32000;1280;48
    ClassName: Header
    IsOffScreen: False

        AutomationId: ShellHeader_LogoutUser
        ControlType: ControlType.Button
        Name: Logout
        HelpText:
        Bounding rectangle: -30889;-31998;48;20
        ClassName: Button
        IsOffScreen: False

        AutomationId: ShellHeader_Tools
        ControlType: ControlType.Button
        Name: Tools
        HelpText:
        Bounding rectangle: -30824;-31998;40;20
        ClassName: Button
        IsOffScreen: False

        AutomationId: ShellHeader_LanguangeSelection
        ControlType: ControlType.ComboBox
        Name:
        HelpText:
        Bounding rectangle: -30768;-31997;46;20
        ClassName: ComboBox
        IsOffScreen: False

            AutomationId:
            ControlType: ControlType.ListItem
            Name:
            HelpText:
            Bounding rectangle: 0;0;0;0
            ClassName: ListBoxItem
            IsOffScreen: True

            AutomationId:
            ControlType: ControlType.ListItem
            Name:
            HelpText:
            Bounding rectangle: 0;0;0;0
            ClassName: ListBoxItem
            IsOffScreen: True

        AutomationId: ShellHeader_Search
        ControlType: ControlType.Custom
        Name:
        HelpText:
        Bounding rectangle: -30907;-31976;182;24
        ClassName: SearchBox
        IsOffScreen: False

            AutomationId: SearchTextBox
            ControlType: ControlType.Edit
            Name:
            HelpText:
            Bounding rectangle: -30907;-31976;182;23
            ClassName: TextBox
            IsOffScreen: False

                AutomationId: VerticalScrollBar
                ControlType: ControlType.ScrollBar
                Name:
                HelpText:
                Bounding rectangle: -30906;-31974;0;0
                ClassName: ScrollBar
                IsOffScreen: True

                AutomationId: HorizontalScrollBar
                ControlType: ControlType.ScrollBar
                Name:
                HelpText:
                Bounding rectangle: -30906;-31974;0;0
                ClassName: ScrollBar
                IsOffScreen: True

                AutomationId: PART_TriggerAction
                ControlType: ControlType.Button
                Name:
                HelpText:
                Bounding rectangle: -30743;-31972;15;15
                ClassName: Button
                IsOffScreen: False

                    AutomationId:
                    ControlType: ControlType.Image
                    Name:
                    HelpText:
                    Bounding rectangle: -30741;-31970;11;11
                    ClassName: Image
                    IsOffScreen: False

        AutomationId: ShellStatus_DashboardButton
        ControlType: ControlType.Button
        Name:
        HelpText: Open your personal dashboard
        Bounding rectangle: -31828;-32000;38;47
        ClassName: Button
        IsOffScreen: False

        AutomationId: ShellStatus_MyTasksButton
        ControlType: ControlType.Button
        Name:
        HelpText: Access your tasks
        Bounding rectangle: -31782;-32000;38;48
        ClassName: Button
        IsOffScreen: False

    AutomationId: Shell_Content
    ControlType: ControlType.Custom
    Name:
    HelpText:
    Bounding rectangle: -32000;-31952;1280;684
    ClassName: Content
    IsOffScreen: False

        AutomationId: ShellContentBackgroundImage
        ControlType: ControlType.Image
        Name:
        HelpText:
        Bounding rectangle: -32000;-31952;1280;684
        ClassName: Image
        IsOffScreen: False

        AutomationId: ShellContent_ButterflyLight
        ControlType: ControlType.Image
        Name:
        HelpText:
        Bounding rectangle: -32000;-31952;0;0
        ClassName: Image
        IsOffScreen: True

        AutomationId: ShellContent_MyTasks
        ControlType: ControlType.Custom
        Name:
        HelpText:
        Bounding rectangle: -31990;-31942;1260;664
        ClassName: MyTasks
        IsOffScreen: False

            AutomationId: Shell_WorkspaceCloseButton
            ControlType: ControlType.Button
            Name:
            HelpText:
            Bounding rectangle: -30757;-31942;27;16
            ClassName: Button
            IsOffScreen: False

            AutomationId: Workspace_ActiveTasks
            ControlType: ControlType.Button
            Name: Workspace
            HelpText:
            Bounding rectangle: -30840;-31922;0;0
            ClassName: Button
            IsOffScreen: True

            AutomationId: Workspace_ProcessMenu
            ControlType: ControlType.Button
            Name: MyTasks
            HelpText:
            Bounding rectangle: -30740;-31922;0;24
            ClassName: Button
            IsOffScreen: False

            AutomationId:
            ControlType: ControlType.Group
            Name: Frequent Tasks
            HelpText:
            Bounding rectangle: -31980;-31888;1237;99
            ClassName: GroupItem
            IsOffScreen: False

            AutomationId:
            ControlType: ControlType.Group
            Name: Administrator
            HelpText:
            Bounding rectangle: -31980;-31784;1237;25
            ClassName: GroupItem
            IsOffScreen: False

            AutomationId:
            ControlType: ControlType.Group
            Name: Sales
            HelpText:
            Bounding rectangle: -31980;-31754;1237;26
            ClassName: GroupItem
            IsOffScreen: False

            AutomationId:
            ControlType: ControlType.Group
            Name: Accounting
            HelpText:
            Bounding rectangle: -31980;-31723;1237;25
            ClassName: GroupItem
            IsOffScreen: False

            AutomationId:
            ControlType: ControlType.Group
            Name: Inventory
            HelpText:
            Bounding rectangle: -31980;-31693;1237;26
            ClassName: GroupItem
            IsOffScreen: False

            AutomationId: VerticalScrollBar
            ControlType: ControlType.ScrollBar
            Name:
            HelpText:
            Bounding rectangle: -31980;-31888;0;0
            ClassName: ScrollBar
            IsOffScreen: True

            AutomationId: HorizontalScrollBar
            ControlType: ControlType.ScrollBar
            Name:
            HelpText:
            Bounding rectangle: -31980;-31888;0;0
            ClassName: ScrollBar
            IsOffScreen: True

            AutomationId: CloseButton
            ControlType: ControlType.Button
            Name:
            HelpText:
            Bounding rectangle: -29576;-31886;16;15
            ClassName: Button
            IsOffScreen: True

            AutomationId: OptionsButton
            ControlType: ControlType.Button
            Name:
            HelpText:
            Bounding rectangle: -29558;-31887;16;16
            ClassName: Button
            IsOffScreen: True

        AutomationId: ShellContent_Dashboard
        ControlType: ControlType.Custom
        Name:
        HelpText:
        Bounding rectangle: -31990;-31942;1260;664
        ClassName: Dashboard
        IsOffScreen: True

            AutomationId: Shell_DashboardTitleImage
            ControlType: ControlType.Image
            Name:
            HelpText:
            Bounding rectangle: -31989;-31941;0;0
            ClassName: Image
            IsOffScreen: True

            AutomationId: Shell_DashboardCloseButton
            ControlType: ControlType.Button
            Name:
            HelpText:
            Bounding rectangle: -30757;-31942;27;16
            ClassName: Button
            IsOffScreen: True

            AutomationId: VerticalScrollBar
            ControlType: ControlType.ScrollBar
            Name:
            HelpText:
            Bounding rectangle: -31980;-31910;0;0
            ClassName: ScrollBar
            IsOffScreen: True

            AutomationId: HorizontalScrollBar
            ControlType: ControlType.ScrollBar
            Name:
            HelpText:
            Bounding rectangle: -31980;-31910;0;0
            ClassName: ScrollBar
            IsOffScreen: True

            AutomationId: Shell_DashboardPartList
            ControlType: ControlType.List
            Name:
            HelpText:
            Bounding rectangle: -30995;-31831;250;540
            ClassName: ListBox
            IsOffScreen: True

                AutomationId:
                ControlType: ControlType.ListItem
                Name: Primavera.Athena.UI.Shell.Model.DashboardPartRuntimeInfo
                HelpText:
                Bounding rectangle: -30994;-31830;248;65
                ClassName: ListBoxItem
                IsOffScreen: True

                    AutomationId:
                    ControlType: ControlType.Image
                    Name:
                    HelpText:
                    Bounding rectangle: -30986;-31824;48;48
                    ClassName: Image
                    IsOffScreen: True

                AutomationId:
                ControlType: ControlType.ListItem
                Name: Primavera.Athena.UI.Shell.Model.DashboardPartRuntimeInfo
                HelpText:
                Bounding rectangle: -30994;-31765;248;65
                ClassName: ListBoxItem
                IsOffScreen: True

                    AutomationId:
                    ControlType: ControlType.Image
                    Name:
                    HelpText:
                    Bounding rectangle: -30986;-31759;48;48
                    ClassName: Image
                    IsOffScreen: True

                AutomationId:
                ControlType: ControlType.ListItem
                Name: Primavera.Athena.UI.Shell.Model.DashboardPartRuntimeInfo
                HelpText:
                Bounding rectangle: -30994;-31700;248;60
                ClassName: ListBoxItem
                IsOffScreen: True

                    AutomationId:
                    ControlType: ControlType.Image
                    Name:
                    HelpText:
                    Bounding rectangle: -30986;-31694;48;48
                    ClassName: Image
                    IsOffScreen: True

                AutomationId:
                ControlType: ControlType.ListItem
                Name: Primavera.Athena.UI.Shell.Model.DashboardPartRuntimeInfo
                HelpText:
                Bounding rectangle: -30994;-31640;248;66
                ClassName: ListBoxItem
                IsOffScreen: True

                    AutomationId:
                    ControlType: ControlType.Image
                    Name:
                    HelpText:
                    Bounding rectangle: -30986;-31634;48;48
                    ClassName: Image
                    IsOffScreen: True

                AutomationId:
                ControlType: ControlType.ListItem
                Name: Primavera.Athena.UI.Shell.Model.DashboardPartRuntimeInfo
                HelpText:
                Bounding rectangle: -30994;-31574;248;65
                ClassName: ListBoxItem
                IsOffScreen: True

                    AutomationId:
                    ControlType: ControlType.Image
                    Name:
                    HelpText:
                    Bounding rectangle: -30986;-31568;48;48
                    ClassName: Image
                    IsOffScreen: True

        AutomationId: ContentPane_MessageBox
        ControlType: ControlType.Custom
        Name:
        HelpText:
        Bounding rectangle: -32000;-31952;0;0
        ClassName: WpfMessageBox
        IsOffScreen: True

    AutomationId: Shell_Status
    ControlType: ControlType.Custom
    Name:
    HelpText:
    Bounding rectangle: -32000;-31268;1280;18
    ClassName: Status
    IsOffScreen: False

    AutomationId: Shell_ExceptionDialog
    ControlType: ControlType.Custom
    Name:
    HelpText:
    Bounding rectangle: -32000;-32000;0;0
    ClassName: DefaultExceptionDialog
    IsOffScreen: True

 

Coordinator
Mar 11, 2009 at 4:09 AM
have you checked the number 3 on this page http://white.codeplex.com/Wiki/View.aspx?title=Other%20questions
Mar 11, 2009 at 9:47 AM

Somehow I finded a solution:

Get the source control from snoop (http://blois.us/Snoop/) and I use the assembly managed injector to send a message to the thread of the application under test:

 

Injector

 

.Launch((IntPtr)this.application.Process.MainWindowHandle, typeof(myclass).Assembly, typeof(myclass).FullName, "SelectCategoriesListMenu");

 

 


In myclass i do this:
public static System.Windows.Application SelectCategoriesListMenu(){

 

System.Windows.

Application root = System.Windows.Application.Current;

 

 

if (root != null)

 

{

SelectMenu(root, "Configurations List");

 

}

 

return root;

 

}

 


In a class of the test project what I do is to get the Application object from the application under test and work with the utility VisualTreeHelper to click on the controls.

This is not the ideal situation but at this time I manged to do the click.

I make another suggestion to the White framework; Make available the Application object of the application under test. This will be great because in some controls like Infragistics I could create a specific class in that application to do the clicks on the controls that don't support UIAutomation.

Coordinator
Mar 22, 2009 at 11:31 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.