使用UIAutomation时,我似乎无法获得对执行右键单击命令时显示的上下文菜单的引用。
以下示例显示了我打开一个新窗口(其中包含一个Windows资源管理器),从可用的DesktopWindows获取正确的引用(请注意我可以将其移动正确)并通过右侧触发上下文菜单的情况-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
我尝试使用window.Popup变量来获取弹出窗口但是为null(不是窗口对象的类型是White.Core.UIItems.WindowItems.WinFormWindow
答案 0 :(得分: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();
答案 1 :(得分:1)
static PopUpMenu GetCurrentPopUpMenu(){
List<Window> windows = WindowFactory.Desktop.DesktopWindows();
foreach(Window w in windows)
{
if(w.Name == "") return w.PopUp;
}
return null;
}