【问题标题】:UIAutomation with ToolStripStatusLabel带有 ToolStripStatusLabel 的 UIAutomation
【发布时间】:2010-11-03 16:19:03
【问题描述】:

我有一个 WinForms 应用程序,但我似乎无法通过 UIAutomation 访问 ToolStripStatusLabel 的文本。 Microsoft implies 表示对 StatusStrips(以及其中的项目)的支持是有限的,但这似乎是一个足够基本的用例,它应该可以工作。

该控件在 UISpy 中显示为 ControlType.Edit,并且看起来只是一个只读文本框,但其值始终与其名称相同,而不是其文本。

UISpy中的属性如下:

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

  State
    IsEnabled:  "True"
    HasKeyboardFocus:   "False"

  Identification
    ClassName:  ""
    ControlType:    "ControlType.Edit"
    Culture:    "(null)"
    AutomationId:   "StatusBar.Pane0"
    LocalizedControlType:   "edit"
    Name:   "My Label"
    ProcessId:  "3972 (*****)"
    RuntimeId:  "42 134002 0"
    IsPassword: "False"
    IsControlElement:   "True"
    IsContentElement:   "True"

  Visibility
    BoundingRectangle:  "(9, 273, 79, 17)"
    ClickablePoint: "48,281"
    IsOffscreen:    "False"

ControlPatterns
  GridItem
    Row:    "0"
    Column: "0"
    RowSpan:    "1"
    ColumnSpan: "1"
    ContainingGrid: ""status bar" "statusStrip""

  Value
    Value:  "My Label"
    IsReadOnly: "True"

基本上,我希望通过某种方式去myLabel.Text = "something" 并能够通过 UIAutomation 以某种方式获得该价值。

【问题讨论】:

    标签: .net windows winforms accessibility ui-automation


    【解决方案1】:

    我不得不通过使用两个带有不同文本的单独标签来解决这个问题,并显示和隐藏适当的标签。这足以满足我的目的(使用 White 进行测试),但我很惊讶 UIAutomation 没有显示文本值 - 这基本上意味着屏幕阅读器无法访问 WinForms 应用程序中状态栏中的所有文本。

    【讨论】:

      【解决方案2】:

      我在检索与您描述的类似的标签文本时从未遇到过问题。事实上,AutomationId 在我的应用程序中甚至是相同的。 ControlType 显示为 ControlType.Edit 的事实具有误导性。例如以下将起作用

      statusText = (string)automationElement.GetCurrentPropertyValue(ValuePattern.ValueProperty);
      

      automationElement 的位置已使用 Find 方法对 ControlType.Edit 进行定位,其中 AutomationId"StatusBar.Pane0"

      【讨论】:

      • 啊,有趣。我下周试试这个!知道为什么它可能会作为编辑控件公开吗?这对我来说很好,但它似乎会误导屏幕阅读器。
      【解决方案3】:

      ToolStripStatusLabel 控件上设置AccessibleName.Text 属性。它适用于我在类似的场景中使用 White:

      statusLabel.Text = statusLabel.AccessibleName = "New status value";

      【讨论】:

        猜你喜欢
        • 2015-01-14
        • 2012-10-06
        • 2013-09-25
        • 2012-09-07
        • 2013-04-17
        • 1970-01-01
        • 1970-01-01
        • 2011-01-23
        • 2016-08-28
        相关资源
        最近更新 更多