如何使用TestStack.White获取窗口

时间:2016-06-15 07:01:06

标签: c# ui-automation

我已经通过调用

获得了顶级窗口
Window win = Desktop.Instance.Windows().Find(...);

但获取子窗口时会发生异常:

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

“TestStack.White.AutomationException”类型的未处理异常   发生在TestStack.White.dll

中      

其他信息:无法获取姓名=姓名

来自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

我没有从TestStack.White https://github.com/TestStack/White找到太多信息。 我怀疑这是因为子窗口不是自动控件。

1 个答案:

答案 0 :(得分:2)

首先,查找所有桌面窗口并不是一个好主意。您应该启动提供应用程序路径的应用程序:

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();