This project is read-only.

Menu Item throws error

Jun 24, 2010 at 5:56 AM

I am Automating a WPF windows application

I have problem with menu which throws error some times
White.Core.UIItems.MenuItems.Menu menuItem=mbHydat.MenuItem("Plant Data", "Weight Check", "Process and Analytical ", "Test Creation");

This fails some times saying "Could not find Menu Item Test Creation"

can anyone please help me to fix this ?

Thanks in advance

Jun 30, 2010 at 6:32 AM
Edited Jun 30, 2010 at 6:32 AM

Have you got the source code?

If you do, check the menu item 'Test Creation', make sure that there is no space or dots is added to the end of 'Test Creation' ('Test Creation ' or 'Test Creation...')

If you don't, I am afraid that you have to guess what the problem is.

Jun 30, 2010 at 6:40 AM

I have source code and "Process and Analytical " as u can see is the only place having a space, and this is happening only some times , i hope this is of becaue of timing  erro , if u know how to use Briks Clock then give some sample code ,


Thanks in Advance


Jul 2, 2010 at 6:43 AM
Edited Jul 2, 2010 at 7:21 AM

I don't know much about 'Briks Clock' in White framework.

But I think you can have a try with the following solution: use basic UI Automation elements (shipped by .Net Framework 3.5) to access the menuItem you mentioned.

Assume that you want to check the menuItems under 'Help' in Windows Calculator, use the following code:

private void ShowMenuItemsUnderHelp()
    //Get the Calculator
    AutomationElement calc = AutomationElement.RootElement.FindFirst(TreeScope.Children,
        new PropertyCondition(AutomationElement.NameProperty, "Calculator"));

    //Get the 'Help' menu item in menubar
    AutomationElement help = calc.FindFirst(TreeScope.Descendants,
        new PropertyCondition(AutomationElement.NameProperty, "Help"));

    //Expand the 'Help' menu item

    //Find all menu items under 'Help'
    AutomationElementCollection menuItems = help.FindAll(TreeScope.Descendants,
        new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem));

Before running this code, make sure that you opened a Windows Calculator and no window covers on it.

Add a break point at the last line (the '}' line), and run it.

When the debugger stops you can watch the AutomationElementCollection 'menuItems', it will have two elements, one is menu item 'Help Topics' and the other is 'About Calculator'.

Further more if you want to 'Click' on the 'Help Topics', use the following code:


Is your problem solved?

Jul 30, 2010 at 4:18 PM

Does anyone know of a fix or workaround to this without using UIA?