【问题标题】:Modal window returning null模态窗口返回 null
【发布时间】:2019-06-12 16:04:52
【问题描述】:

我正在尝试使用 teststack.white 自动化流程

 var modalWindows = mainwindow.ModalWindows();

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

但它返回 null

inspect.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 文档中找到任何有用的信息

【问题讨论】:

  • 而不是.Where().FirstOrDefault() 尝试.Single().Where() 在这种情况下不会返回所需的值。
  • 根据您共享的“子窗口”信息,它显示为Window.IsModal: false。你确定你应该能够得到这个子窗口吗?

标签: c# ui-automation


【解决方案1】:

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

您可以使用.Single() 代替这个(但只有当只有一个元素时)。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-08
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    相关资源
    最近更新 更多