Unable to locate Menu items in MenuBar

Aug 26, 2008 at 1:23 PM

I am trying to use White for automated testing of a .net 2.0 application. I am trying to find the "File" menu item on the menubar using UISpy but I cannot get a handle to the control. The output window shows me the following error when I try to hover mode to search for the control:
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)

The designer code for creating the menu item is:
private void InitializeComponent()
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();

// menuStrip1
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(292, 24);
this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1";

// fileToolStripMenuItem



this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);
this.fileToolStripMenuItem.Text = "File";

// MainForm
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.IsMdiContainer = true;
this.Name = "MainForm";
this.Text = "Main Form";



My problem is that I am unable to navigate the menu because I am unable to search for the control. The same is true for toolstrip. Please help.

Aug 27, 2008 at 8:36 PM
can you post your apps code, so i can help you
Aug 28, 2008 at 4:42 AM

In addition to the code mentioned above I have the following variables defined in the designer:



private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;



I wrote the following code for testing the app:

Window window = application.GetWindow("Main Form", Core.Factory.InitializeOption.NoCache);
SearchCriteria searchCriteria = UIItems.Finders.SearchCriteria.ByAutomationId("menuStrip1");
MenuBar menuBar = window.Get(searchCriteria) as UIItems.WindowStripControls.MenuBar;
Menu menu = menuBar.TopLevelMenu.Find("File");  //menu variable is null.

I also tried to search using:

menuBar.MenuItem( "File") but this also returns null.


Thanks alot,


Sep 1, 2008 at 5:18 AM
Hi Nitin,
This same problem was by me. For some reason uispy did not show me the information for the file menu. I tried UI Automation verify and it worked.
Hope this helps.
Sep 2, 2008 at 11:36 AM
No, I was not able to find the "File" menu item using UIAutomationVerify. It seems that UI automation does not support winforms menustrip, toolstripmenuitem etc. There needs to be another way to access the controls on the menu bar because clicking on the menu items is a pretty basic requirement.
Sep 2, 2008 at 8:35 PM
There is a known issue in UIA for MenuStrip in winforms where on certain version of OS it cannot find anything inside the menubar. When I faced this in some project I had to use keyboard directly for this. I am not sure whether .NET 3.1 fixes this or not.
Sep 3, 2008 at 3:51 AM
Thats fine. But is there a way around this. If my next form is invoke on the click of a toolstripmenuitem. Can I invoke the form using some other technique, because as of now I am unable to proceed forwards.
Thanks & Regards,
Jan 28, 2009 at 10:53 AM
Edited Jan 28, 2009 at 10:55 AM
Hi Vivek/Nitin,
could you please confirm this that, whether this Known issue is Fixed in .NET 3.5?
i.e. UIA for MenuStrip in winforms doesn't provide a handle for the same.

with regards,
Jan 31, 2009 at 10:23 AM
Does this solve your problem.
Feb 2, 2009 at 2:44 AM
Hi Vivek,
This is something relevant to the use of NUnit, and I am using .NET 3.5's inbuilt facilities, i.e. UIAutomation libraries.

with regards,

May 16, 2009 at 11:14 PM

Has there been any resolution to this problem. I cannot automate menu items either. I'm working with winforms on .net 3.5. I have also used UIAutomationVerify to inspect the menubar and I cannot see the menuitems in there either. How can I progress/workaround this?

May 19, 2009 at 11:53 AM

Appologies. My problem did indeed turn out to be the nunit (resharper) problem. Now I'm turning out to be quite productive. Excellant work, thanks.

Aug 20, 2009 at 12:04 PM

I am having hte same issue with the File Menu issue.  Can anyone point me into the nunit resharper problem mentioned in this mail?

Nov 12, 2009 at 4:18 AM
Edited Nov 12, 2009 at 4:19 AM


hi  try this

MenuBar menuBar = window2.MenuBar;            (window2 is your application window boject)
                    Menu Menu = menuBar.MenuItem("File");

Nov 13, 2009 at 2:28 PM

Adding this app.config file to the NUnit project will solve the issue for running through the NUnit GUI test runner.  This is the same config file that needs to be added to a project using WatiN:

 <?xml version="1.0" encoding="utf-8" ?>
    <sectionGroup name="NUnit">
      <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
      <!-- Valid values are STA,MTA. Others ignored. -->
      <add key="ApartmentState" value="STA" />


Dec 16, 2009 at 3:38 PM

I'm also running into a problem with the menu not being found, although it's inconsistent. Sometimes it works and sometimes it doesn't if I run the test several times. I think it may partially be a timing issue, but I'm not sure how to fix it. It doesn't even hit the Assert or Click functions in my code, it just throws the exception on the FileArrestMenuItem declaration. Any ideas?

Window MainWindow = GlobalApplication.GetWindow(MainWindowName); //Handler for Main Window

White.Core.UIItems.WindowStripControls.MenuBar FileMenu = MainWindow.MenuBar;

White.Core.UIItems.MenuItems.Menu FileArrestMenuItem = FileMenu.MenuItemBy(SearchCriteria.ByText("File"), SearchCriteria.ByText("Arrest"), SearchCriteria.ByText("Create"));
Assert.AreEqual("Create", FileArrestMenuItem.Name.ToString(), "File->Arrest->Create menu item is missing.");

and the error message:

Test method Test.WPF.Client.Controls.UnitTest1.PersonWindowPass threw exception:  Bricks.BricksException: Error invoking MenuBar.MenuItemBy --->  White.Core.Factory.UIItemSearchException: Could not find Menu Name=Search.

Jun 9, 2010 at 8:47 AM
Edited Jun 9, 2010 at 9:19 AM

I met the same issue with Sneemaster. It would highly appreciate if anyone can help in this.


Jun 9, 2010 at 10:07 AM
Window MainWindow = GlobalApplication.GetWindow(MainWindowName); //Handler for Main Window

White.Core.UIItems.WindowStripControls.MenuBar FileMenu = MainWindow.MenuBar;
White.Core.UIItems.MenuItems.Menu mnTestCreation = FileMenu .MenuItem("Level1", "Level2", "Level3", "Level4");

if still your menuitem returns null, check if there is any space before or after on the menu text
Jun 10, 2010 at 9:02 AM
Hi goldymanikoth,

I already checked the space. It runs not stable. We always get Level1 menu. About Level2, Level3, Level 4. Sometimes I can get it, sometimes not. I don't what is this problem.


goldymanikoth wrote:

From: goldymanikoth

Window MainWindow = GlobalApplication.GetWindow(MainWindowName); //Handler for Main Window

White.Core.UIItems.WindowStripControls.MenuBar FileMenu = MainWindow.MenuBar;
White.Core.UIItems.MenuItems.Menu mnTestCreation = FileMenu .MenuItem("Level1", "Level2", "Level3", "Level4");

if still your menuitem returns null, check if there is any space before or after on the menu text

Jun 15, 2010 at 8:53 AM

My code below:

MenuBar mainMenu = mainWindow.MenuBar;
Menu mnRoomSetting = mainMenu.MenuItem("Tools", "This provider configuration", "Timebook setup", "Room setting");


And the error message is :

Opus.AppointmentBookUITesting (TestFixtureSetUp):
Bricks.BricksException : Error invoking MenuBar.MenuItem
  ----> White.Core.Factory.UIItemSearchException : Could not find Menu Name=Timebook setup


Please help me in this. Who faced this problem before and found out the solution?

Aug 11, 2011 at 6:30 PM

This windows update fixed it for me: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13821

(Thanks to Michael Bernstein, via http://social.msdn.microsoft.com/Forums/en-US/windowsaccessibilityandautomation/thread/061f9ef1-2e34-4176-b3f2-530ef3468047)



Nov 23, 2011 at 6:00 AM

Using this patch can we resolve following issue:

My C# application consists of Toolstrip and toolstrip buttons in it. Nunit returns null when i try to retrieve ToolStripButton.

Any Fix?