ui-automation – 使用White / UIAutomation如何获得右键单击上下文菜单

当使用UIAutomation时,我似乎无法获得对执行右键单击命令时显示的上下文菜单的引用.

下面的例子显示了一个案例,我打开了一个新的窗口,其中包含一个(Windows资源管理器),从可用的DesktopWindows获得正确的引用(请注意我可以将其移动),并通过右键单击触发上下文菜单.

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

我试图使用window.Popup变量来获取弹出窗口但是为null(不是窗口对象的类型是Wh​​ite.Core.UIItems.WindowItems.WinFormWindow

最佳答案 看起来你在这里回答了你自己的问题:
http://white.codeplex.com/discussions/250129

😉

编辑:我找到了一种方法:

public static PopUpMenu getContextMenu(this API_GuiAutomation guiAutomation)     
    {
        try
        {
            var emptyWindow = guiAutomation.desktopWindow("");
            return emptyWindow.Popup;
        }
        catch
        {
        }
        return null;
    }

然后可以这样消费:

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