【问题标题】:Using White/UIAutomation How to get a right-click context menu使用 White/UIAutomation 如何获得右键单击上下文菜单
【发布时间】:2012-08-29 21:52:32
【问题描述】:

使用 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

【问题讨论】:

    标签: ui-automation white-framework


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:
      static PopUpMenu GetCurrentPopUpMenu(){
      
          List<Window> windows = WindowFactory.Desktop.DesktopWindows();
          foreach(Window w in windows)
          {
              if(w.Name == "") return w.PopUp;
          }
          return null;
      }
      

      【讨论】:

        猜你喜欢
        • 2011-12-08
        • 1970-01-01
        • 2011-09-30
        • 1970-01-01
        • 2016-02-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多