模态窗口返回null

时间:2019-06-12 07:11:46

标签: c# ui-automation

我正在尝试使用 teststack.white 使过程自动化。我的主窗口为 mainwindow 。我正在尝试使用以下代码获取子窗口。

 var modalWindows = mainwindow.ModalWindows();

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

但是它返回null

inspector.exe的子窗口信息

How found:  Selected from tree...
Name:   "Terminal Pattern"
ControlType:    UIA_WindowControlTypeId (0xC370)
LocalizedControlType:   "window"
BoundingRectangle:  {l:617 t:160 r:1303 b:880}
IsEnabled:  true
IsOffscreen:    false
IsKeyboardFocusable:    true
HasKeyboardFocus:   false
AcceleratorKey: ""
AccessKey:  ""
ProcessId:  32716
RuntimeId:  [2A.6B1C2A]
AutomationId:   ""
FrameworkId:    "WPF"
ClassName:  "Window"
NativeWindowHandle: 0x6B1C2A
IsControlElement:   true
IsContentElement:   true
ProviderDescription:    "[pid:29772,providerId:0x6B1C2A Main:Nested [pid:32716,providerId:0x6B1C2A Main(parent link):Unidentified Provider (managed:MS.Internal.Automation.ElementProxy, PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)]; Nonclient:Microsoft: Non-Client Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]"
IsPassword: false
ItemStatus: ""
ItemType:   ""
IsRequiredForForm:  false
HelpText:   ""
ClickablePoint: {x:968 y:551}
Orientation:    0
IsDialog:   [Not supported]
LegacyIAccessible.ChildId:  0
LegacyIAccessible.DefaultAction:    ""
LegacyIAccessible.Description:  ""
LegacyIAccessible.Help: ""
LegacyIAccessible.KeyboardShortcut: ""
LegacyIAccessible.Name: "Terminal Pattern"
LegacyIAccessible.Role: window (0x9)
LegacyIAccessible.State:    focusable (0x100000)
LegacyIAccessible.Value:    ""
Transform.CanMove:  true
Transform.CanResize:    true
Transform.CanRotate:    false
Window.CanMaximize: true
Window.CanMinimize: true
Window.IsModal: false
Window.IsTopmost:   false
Window.WindowInteractionState:  ReadyForUserInteraction (2)
Window.WindowVisualState:   Normal (0)
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:    true
IsTableItemPatternAvailable:    false
IsTablePatternAvailable:    false
IsTextChildPatternAvailable:    false
IsTextEditPatternAvailable: false
IsTextPatternAvailable: false
IsTextPattern2Available:    false
IsTogglePatternAvailable:   false
IsTransformPatternAvailable:    true
IsTransform2PatternAvailable:   false
IsValuePatternAvailable:    false
IsVirtualizedItemPatternAvailable:  false
IsWindowPatternAvailable:   true
IsCustomNavigationPatternAvailable: false
IsSelectionPattern2Available:   false
FirstChild: (null) title bar
LastChild:  "Cancel" button
Next:   "c# - How to get window using TestStack.White - Stack Overflow - Google Chrome" pane
Previous:   "Microsoft Visual Studio" window
Other Props:    Object has no additional properties
Children:   (null) title bar
    "Pattern" group
    "" check box
    "Field cables terminate on right" text
    "Preview" group
    "i" text
    "To set the terminal class, select a terminal type before creating the pattern.
Once the pattern is created, the type of indivi
    "OK" button
    "Cancel" button
Ancestors:  "Desktop 1" pane
    [ No Parent ]

我是C#和自动化的新手,无法从teststack.white文档中找到任何有用的信息

1 个答案:

答案 0 :(得分:0)

我已经重新检查了问题,答案是不使用.Where()

相反,您可以使用.Single()但仅当只有一个元素时)。

如果不是这种情况,则可以使用.FirstOrDefault().Name,这将成为您的第一个要素,就像您现在要尝试做的一样。