This project is read-only.

ElementNotAvailableException while retrieving popmenu

Dec 1, 2010 at 11:21 AM

ElementNotAvailableException while retrieving popmenu

I am in a process of automating a windows application using White project. 

In my windows application, I have dialog which has tabs in it.

In one of the tab, I have DataGrid and a ContextMenuStrip attached to it.

In my test application, when I try to open the ContextMenuStrip and click the first menu, I receive Object reference not set to an instance of an object (NullReferenceException).

Below is the code snippet I used:

// Namespace
using WhiteList = White.Core.UIItems.ListView;

Window wndIMI = application.GetWindows().Find(wnd => (wnd.Title.IndexOf(windowTitle) > -1));

SearchCriteria schTab = SearchCriteria.ByControlType(ControlType.TabItem);
TabPage tabParameter = wndIMI.Get<TabPage>(schTab.AndByText("Identifiers"));

SearchCriteria schListView = SearchCriteria.ByControlType(ControlType.DataGrid).AndIndex(0);
WhiteList dgView = (WhiteList)wndIMI.Get<WhiteList>(schListView);

PopUpMenu mnuPopup;
mnuPopup = wndIMI.Popup;
Console.WriteLine(">>>Window has popup menu " + wndIMI.HasPopup());
Console.WriteLine(">>>Popup menu count " + mnuPopup.Items.Count);

Above code returns FALSE on wndIMI.HasPopup() and exception occurs on the mnuPopup.Items.Count.

When I try to find out the reason of the exception using UISpy.exe, I get below exception and here is the stack trace.

Time Stamp : 12/1/2010 2:59 PM
Element : "menu item" "Add..."
Name : ElementNotAvailableException
Message : Exception of type 'System.Windows.Automation.ElementNotAvailableException' was thrown.
Stack Trace :    at MS.Internal.Automation.UiaCoreApi.CheckError(Int32 hr)
   at MS.Internal.Automation.UiaCoreApi.UiaNavigate(SafeNodeHandle hnode, NavigateDirection direction, Condition condition, UiaCacheRequest request)
   at System.Windows.Automation.AutomationElement.Navigate(NavigateDirection direction, Condition condition, CacheRequest request)
   at System.Windows.Automation.TreeWalker.GetParent(AutomationElement element)
   at UISpy.Base.Node.ParentElement(AutomationElement element)

Focus Change Event
Time Stamp : 12/1/2010 2:59:29 PM
Element : "menu item" "Add..."
Object ID : -4
Child ID : 1

Does anyone get any idea to solve this issue?

Thanks in advance

Rajkumar Subramanian