White/UIAutomationの使用右クリックコンテキストメニューを取得する方法
-
27-10-2019 - |
質問
uiAutomationを使用する場合、右クリックがコマンドが実行されたときに表示されるコンテキストメニューへの参照を取得できないようです。
次の例は、(内部にWindows Explorer)を備えた新しいウィンドウを開き、利用可能な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でした(ウィンドウオブジェクトがwhite.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();
他のヒント
static PopUpMenu GetCurrentPopUpMenu(){
List<Window> windows = WindowFactory.Desktop.DesktopWindows();
foreach(Window w in windows)
{
if(w.Name == "") return w.PopUp;
}
return null;
}
所属していません StackOverflow