2011-03-17 51 views
4

當使用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變量獲得彈出但這是空(不是窗口對象的類型爲White.Core.UIItems.WindowItems.WinFormWindow

回答

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(); 
+0

是的,我做到了,那工作:) – 2011-06-07 14:31:38

1
static PopUpMenu GetCurrentPopUpMenu(){ 

    List<Window> windows = WindowFactory.Desktop.DesktopWindows(); 
    foreach(Window w in windows) 
    { 
     if(w.Name == "") return w.PopUp; 
    } 
    return null; 
} 
相關問題