2016-06-15 62 views
1
拿到窗口

我已經通過調用到達頂級窗口:如何使用TestStack.White

Window win = Desktop.Instance.Windows().Find(...); 

但出現異常,讓子窗口時:

IUIItem item = win.Get(SearchCriteria.ByText("The Name")); 

未處理的異常類型「TestStack.White.AutomationException」 發生在TestStack.White.dll

其他信息:無法獲取NAME =名字從Inspect.exe

子窗口信息:從TestStack.White https://github.com/TestStack/White

Name:         "The Name" 
ControlType:       UIA_PaneControlTypeId (0xC371) 
LocalizedControlType:     "Dialog" 
BoundingRectangle:     {l:96 t:38 r:1917 b:1078} 
IsEnabled:       true 
IsKeyboardFocusable:     false 
HasKeyboardFocus:      false 
ProcessId:       15496 
RuntimeId:       [2A.140BD8] 
FrameworkId:       "Win32" 
ClassName:       "#32770" 
NativeWindowHandle:     0x140BD8 
IsControlElement:      false 
IsContentElement:      false 
ProviderDescription:     "[pid:14492,hwnd:0x140BD8 Main:Microsoft: Container Proxy (unmanaged:uiautomationcore.dll); Nonclient:Microsoft: Non-Client Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]" 
LegacyIAccessible.ChildId:   0 
LegacyIAccessible.Name:    "The Name" 
LegacyIAccessible.Role:    Dialog (0x12) 
LegacyIAccessible.State:    (0x100000) 
IsAnnotationPatternAvailable:   false 
IsDragPatternAvailable:    false 
IsDockPatternAvailable:    false 
IsDropTargetPatternAvailable:   false 
IsExpandCollapsePatternAvailable:  false 
IsGridItemPatternAvailable:   false 
IsGridPatternAvailable:    false 
IsInvokePatternAvailable:    false 
IsItemContainerPatternAvailable:  false 
IsLegacyIAccessiblePatternAvailable: true 
IsMultipleViewPatternAvailable:  false 
IsObjectModelPatternAvailable:  false 
IsRangeValuePatternAvailable:   false 
IsScrollItemPatternAvailable:   false 
IsScrollPatternAvailable:    false 
IsSelectionItemPatternAvailable:  false 
IsSelectionPatternAvailable:   false 
IsSpreadsheetItemPatternAvailable: false 
IsSpreadsheetPatternAvailable:  false 
IsStylesPatternAvailable:    false 
IsSynchronizedInputPatternAvailable: false 
IsTableItemPatternAvailable:   false 
IsTablePatternAvailable:    false 
IsTextChildPatternAvailable:   false 
IsTextEditPatternAvailable:   false 
IsTextPatternAvailable:    false 
IsTextPattern2Available:    false 
IsTogglePatternAvailable:    false 
IsTransformPatternAvailable:   false 
IsTransform2PatternAvailable:   false 
IsValuePatternAvailable:    false 
IsVirtualizedItemPatternAvailable: false 
IsWindowPatternAvailable:    false 

我還沒有發現太多的信息。 我懷疑這是因爲子窗口不是自動化控件。

回答

1

首先,找到所有桌面窗口並不是一個好主意。你應該啓動應用程序提供應用程序路徑:

TestStack.White.Application app = TestStack.White.Application.Launch(applicatonFullPath); 

那麼你應該得到主窗口爲您的應用程序:

mainWinDow = app.GetWindows().FirstOrDefault(w => w.Name == "YOUR MAIN WINDOW NAME"); 

你的子窗口可能是一個模態窗口。你可以像他一樣得到它:

var modalWindows = mainWinDow.ModalWindows(); 

modalWindow = modalWindows.Where(x => x.Name == "The Name").FirstOrDefault();