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

控件在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以某种方式获得该值。

有帮助吗?

解决方案

ToolStripStatusLabel 控件上的 .Text 之外设置 AccessibleName 属性。在类似的情况下,它适用于我使用White:

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

其他提示

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

我从来没有遇到过类似于你所描述的标签文本的问题。事实上, AutomationId 在我的应用程序中甚至是相同的。 ControlType 显示为 ControlType.Edit 这一事实具有误导性。例如以下将起作用

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

使用 ControlType.Edit 的Find方法找到 automationElement ,其中 AutomationId " StatusBar.Pane0"

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top