Using White/UIAutomation How to get a right-click context menu

Mar 17, 2011 at 5:38 PM

When using UIAutomation I can't seem to be able to get a reference to the context menu that is shown when a right click is command is executed.
The following example shows a case where I opened up a new window with a (windows explorer inside it),got its correct reference from the available DesktopWindows (note that I can move it ok) and triggered the context menu via a right-click. 

var windowName = "This is a WinForms window: {0}".format(3.randomLetters());
var topPanel = O2Gui.open<Panel>(windowName,600,200 );
var webBrowser = topPanel.add_WebBrowser_Control();

webBrowser.open("".o2Temp2Dir());
var guiAutomation = new API_GuiAutomation();
var window = guiAutomation.desktopWindow(windowName);
window.move(0,0);
window.mouse_MoveTo();
guiAutomation.mouse().rightClick(); 

window.infoTypeName();
return window.Popup;

//O2File:API_GuiAutomation.cs
//O2Ref:White.Core.dll 
//O2Ref:UIAutomationClient.dll

I tried to use the window.Popup variable to get the popup but that was null (not that the window object is of type White.Core.UIItems.WindowItems.WinFormWindow

Mar 17, 2011 at 11:41 PM

I found a way to do this:

		public static PopUpMenu getContextMenu(this API_GuiAutomation guiAutomation)    	

 

		{
			try
			{
				var emptyWindow = guiAutomation.desktopWindow("");
				return emptyWindow.Popup;
			}
			catch
			{
			}
			return null;
		}

 

which can then be consumed like this:

		var contextMenu =  guiAutomation.getContextMenu();
		contextMenu.menu("Git Clone...").click();