2011-05-06 41 views
6

我正在使用編輯器中的彈出窗口提供列表框中的對象,以便用戶雙擊以便將其添加到文檔中。我試圖使用Microsoft提供的Automation API爲應用程序創建自動化測試,但我無法弄清楚如何獲取Popup控件的AutomationElement,因爲它與我的編輯器及其控件不同。有人知道如何獲得WPF Popup的AutomationElement嗎?獲取WPF彈出窗口的自動化元素

回答

2

我最終不得不在桌面啓動,並通過自動化樹使用一些非常特定的PropertyConditions與AndCondition結合使用查詢,並使用TreeScope.Descendants作爲我的查詢參數。

0

我從主窗口中的孩子得到了彈出彈出AutomationElement(OpenFileDialog在我的情況):

// I had automationElement for main window in advance 
AutomationElement mainWindow = ... 

// Some condition to distinguish your popup from others 
// if you may have more than one popup. 
// Otherwise this condition might check ControlType == Window 
Condition popupCondition = ... 

var popup = mainWindow.FindFirst(TreeScope.Children, popupCondition);