Wpf窗口识别问题 [英] Wpf Window Identification problem

查看:68
本文介绍了Wpf窗口识别问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我在使用CodedUI识别WPF应用程序中的主窗口时遇到问题。我不能使用窗口标题作为标识符,因为它可以是不同的,因为应用程序已本地化为不同的语言。

I have a problem with identifying main window in my WPF application using CodedUI. I cannot use window title as identificator because it can be different as app is localized into different languages.

在录制期间,我的窗口有时保存如下:

During recording my window is saved sometimes like this:

< TopLevelWindow ControlType =" Window" ID = QUOT; UILoginWindow"的FriendlyName = QUOT;登录" SpecialControlType = QUOT;无" SessionId =" 4458982">

          < TechnologyName> MSAA< / TechnologyName>

          < WindowTitles>

            < WindowTitle>登录< / WindowTitle>

          < / WindowTitles>

          < SearchConfigurations>

            < SearchConfiguration> VisibleOnly< / SearchConfiguration>

          < / SearchConfigurations>

          < AndCondition Id =" SearchCondition">

            < PropertyCondition Name =" Name"> Login< / PropertyCondition>

            < PropertyCondition Name =" ClassName" Operator =" Contains"> HwndWrapper< / PropertyCondition>

            < PropertyCondition Name =" ControlType"> Window< / PropertyCondition>

          < / AndCondition>

          < SupportLevel> 1< / SupportLevel>

          <后代> ...

<TopLevelWindow ControlType="Window" Id="UILoginWindow" FriendlyName="Login" SpecialControlType="None" SessionId="4458982">
          <TechnologyName>MSAA</TechnologyName>
          <WindowTitles>
            <WindowTitle>Login</WindowTitle>
          </WindowTitles>
          <SearchConfigurations>
            <SearchConfiguration>VisibleOnly</SearchConfiguration>
          </SearchConfigurations>
          <AndCondition Id="SearchCondition">
            <PropertyCondition Name="Name">Login</PropertyCondition>
            <PropertyCondition Name="ClassName" Operator="Contains">HwndWrapper</PropertyCondition>
            <PropertyCondition Name="ControlType">Window</PropertyCondition>
          </AndCondition>
          <SupportLevel>1</SupportLevel>
          <Descendants> ...

,有时像这样:

< TopLevelWindow ControlType =" Window" ID = QUOT; UIWpfWindow"的FriendlyName = QUOT; WPF" SpecialControlType = QUOT;无" SessionId =" 1837502">

          < TechnologyName> UIA< / TechnologyName>

          < WindowTitles>

            < WindowTitle>登录< / WindowTitle>

          < / WindowTitles>

          < AndCondition>

            < PropertyCondition Name =" ControlType"> Window< / PropertyCondition>

            < PropertyCondition Name =" ClassName" Operator =" Contains"> HwndWrapper< / PropertyCondition>

          < / AndCondition>

          < SupportLevel> 0< / SupportLevel>

          <后代> ...

<TopLevelWindow ControlType="Window" Id="UIWpfWindow" FriendlyName="Wpf" SpecialControlType="None" SessionId="1837502">
          <TechnologyName>UIA</TechnologyName>
          <WindowTitles>
            <WindowTitle>Login</WindowTitle>
          </WindowTitles>
          <AndCondition>
            <PropertyCondition Name="ControlType">Window</PropertyCondition>
            <PropertyCondition Name="ClassName" Operator="Contains">HwndWrapper</PropertyCondition>
          </AndCondition>
          <SupportLevel>0</SupportLevel>
          <Descendants> ...

我需要它通过AutomationID或ClassName工作:

I need it to work by AutomationID or by ClassName:

< AndCondition Id =" SearchCondition">

        < PropertyCondition Name =" ControlType"> Window< / PropertyCondition>

        < PropertyCondition Name =" ClassName"> CustomLoginWindow< / PropertyCondition>

        < PropertyCondition Name =" AutomationId"> MyLoginWindow< / PropertyCondition>

< / AndCondition>

<AndCondition Id="SearchCondition">
        <PropertyCondition Name="ControlType">Window</PropertyCondition>
        <PropertyCondition Name="ClassName">CustomLoginWindow</PropertyCondition>
        <PropertyCondition Name="AutomationId">MyLoginWindow</PropertyCondition>
</AndCondition>

UISpy正确显示我窗口的这些属性:

UISpy correctly shows these properties for my window:

AutomationElement

 一般辅助功能

    ACCESSKEY:&NBSP;&NBSP;&NBSP; "&$; b $ b    AcceleratorKey:&NBSP;&NBSP;&NBSP; "&$; b $ b    IsKeyboardFocusable:&NBSP;&NBSP;&NBSP; "True"&b $ b    LabeledBy:&NBSP;&NBSP;&NBSP; "(null)"

   帮助文件:&NBSP;&NBSP;&NBSP; ""



 州

   的IsEnabled:&NBSP;&NBSP;&NBSP; "True"&b $ b    HasKeyboardFocus:&NBSP;&NBSP;&NBSP; "假"&b ​​

 身份证明
   的产品类别:&NBSP;&NBSP;&NBSP; "CustomLoginWindow"


    ControlType:&NBSP;&NBSP;&NBSP; "ControlType.Window"

   文化:&NBSP;&NBSP;&NBSP; "(null)"

   的的AutomationID:&NBSP;&NBSP;&NBSP; "MyLoginWindow"


    LocalizedControlType:&NBSP;&NBSP;&NBSP; "窗口"

   名称:&NBSP;&NBSP;&NBSP; "&$; b $ b   的ProcessID:&NBSP;&NBSP;&NBSP; "4076(壳牌)"&
    RuntimeId:&NBSP;&NBSP;&NBSP; "42 1576384"&
    IsPassword:&NBSP;&NBSP;&NBSP; "False"

    IsControlElement:&NBSP;&NBSP;&NBSP; "True"&b $ b    IsContentElement:&NBSP;&NBSP;&NBSP; "真实"



 可见性

    BoundingRectangle:&NBSP;&NBSP;&NBSP; "(804,377,370,230)" b $ b    ClickablePoint:&NBSP;&NBSP;&NBSP; "989,492"&
    IsOffscreen:&NBSP;&NBSP;&NBSP; "假"&b ​​
$
ControlPatterns

 窗口

    CanMaximize:&NBSP;&NBSP;&NBSP; "False"

    CanMinimize:&NBSP;&NBSP;&NBSP; "False"

    IsModal:&NBSP;&NBSP;&NBSP; "False"

    WindowVisualState:&NBSP;&NBSP;&NBSP; "正常"

    WindowInteractionState:&NBSP;&NBSP;&NBSP; "ReadyForUserInteraction"&
    IsTopmost:&NBSP;&NBSP;&NBSP; "False"

AutomationElement
  General Accessibility
    AccessKey:    ""
    AcceleratorKey:    ""
    IsKeyboardFocusable:    "True"
    LabeledBy:    "(null)"
    HelpText:    ""

  State
    IsEnabled:    "True"
    HasKeyboardFocus:    "False"

  Identification
    ClassName:    "CustomLoginWindow"
    ControlType:    "ControlType.Window"
    Culture:    "(null)"
    AutomationId:    "MyLoginWindow"
    LocalizedControlType:    "window"
    Name:    ""
    ProcessId:    "4076 (Shell)"
    RuntimeId:    "42 1576384"
    IsPassword:    "False"
    IsControlElement:    "True"
    IsContentElement:    "True"

  Visibility
    BoundingRectangle:    "(804, 377, 370, 230)"
    ClickablePoint:    "989,492"
    IsOffscreen:    "False"

ControlPatterns
  Window
    CanMaximize:    "False"
    CanMinimize:    "False"
    IsModal:    "False"
    WindowVisualState:    "Normal"
    WindowInteractionState:    "ReadyForUserInteraction"
    IsTopmost:    "False"

目前我找不到任何控件,我的第一次测试失败了。请让我知道我需要做些什么才能让它发挥作用。

Currently I cannot find any controls, and my very first test fails. Please let me know what I need to do to make it work.

提前致谢。

 

推荐答案

如果您确定ClassName为"CustomLoginWindow",请将其替换为Window的SearchCondition。

If you are sure about the ClassName being "CustomLoginWindow", replace it in the SearchCondition for the Window.

< ; PropertyCondition Name =" ClassName"> CustomLoginWindow< / PropertyCondition>

<PropertyCondition Name="ClassName">CustomLoginWindow</PropertyCondition>

这是否有效?

您不能将AutomationId用于TopLevelWindow,因为它是特定于技术的属性,而不是窗口属性。我们在桌面下进行窗口搜索以找到顶层窗口,我们从中逐步向下钻取以查找后代控件。

You cannot use AutomationId for the TopLevelWindow since it is a technology specific property and not a window property. We do a window search under desktop to find the top level window, from which we drill down recursively to find descendant controls.

尝试在回放设置中使用智能匹配选项;但是我怀疑这种情况在这种情况下会有效,因为不同文化名称可能会发生很大变化。

Try using the smart match option in playbacksettings; but I doubt that will work in this case since the name might change considerably across culture.


这篇关于Wpf窗口识别问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆