Question

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

Was it helpful?

Solution

Looks like you answered your own question here: http://white.codeplex.com/discussions/250129
;)

EDIT: 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();

OTHER TIPS

static PopUpMenu GetCurrentPopUpMenu(){

    List<Window> windows = WindowFactory.Desktop.DesktopWindows();
    foreach(Window w in windows)
    {
        if(w.Name == "") return w.PopUp;
    }
    return null;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top