Reputation: 2317
I have already get the top level Window by calling:
Window win = Desktop.Instance.Windows().Find(...);
But exception occurs when getting sub window:
IUIItem item = win.Get(SearchCriteria.ByText("The Name"));
An unhandled exception of type 'TestStack.White.AutomationException' occurred in TestStack.White.dll
Additional information: Failed to get Name=The Name
Sub window info from Inspect.exe:
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
I haven't found too much info from TestStack.White https://github.com/TestStack/White. I suspect it is because the sub window isn't an Automation control.
Upvotes: 1
Views: 5624
Reputation: 146
First of all it is not a good idea to look for all desktop windows. You should launch your application providing application path:
TestStack.White.Application app = TestStack.White.Application.Launch(applicatonFullPath);
Then you should get main window for your application:
mainWinDow = app.GetWindows().FirstOrDefault(w => w.Name == "YOUR MAIN WINDOW NAME");
Your sub window is probably a modal window. You can get it like his:
var modalWindows = mainWinDow.ModalWindows();
modalWindow = modalWindows.Where(x => x.Name == "The Name").FirstOrDefault();
Upvotes: 3