使用 White/UIAutomation 如何获取右键单击上下文菜单

发布于 2024-10-23 23:47:37 字数 820 浏览 5 评论 0原文

使用 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 变量来获取弹出窗口,但该变量为空(并不是窗口对象的类型为 White.Core.UIItems.WindowItems.WinFormWindow

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自由如风 2024-10-30 23:47:37

看起来您在这里回答了自己的问题: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();

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();
厌倦 2024-10-30 23:47:37
static PopUpMenu GetCurrentPopUpMenu(){

    List<Window> windows = WindowFactory.Desktop.DesktopWindows();
    foreach(Window w in windows)
    {
        if(w.Name == "") return w.PopUp;
    }
    return null;
}
static PopUpMenu GetCurrentPopUpMenu(){

    List<Window> windows = WindowFactory.Desktop.DesktopWindows();
    foreach(Window w in windows)
    {
        if(w.Name == "") return w.PopUp;
    }
    return null;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文