Question

I have a WinForms app, and I can't seem to access the text of a ToolStripStatusLabel through UIAutomation. Microsoft implies that the support for StatusStrips (and presumably items within them) is limited, but this seems like a basic enough use case that it should work.

The control shows up with ControlType.Edit in UISpy, and appears to just be read-only text box, however its value is always the same as its name, not its text.

The properties in UISpy are as follows:

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"

Basically, I'm hoping for some way to go myLabel.Text = "something" and be able to get that value out somehow through UIAutomation.

Was it helpful?

Solution

Set the AccessibleName property in addition to .Text on the ToolStripStatusLabel control. It works for me using White in a similar scenario:

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

OTHER TIPS

I've had to work around this by having two separate labels with different text, and showing and hiding the appropriate one. This is enough for my purposes (testing with White), but I'm very surprised that UIAutomation doesn't surface the text value - it basically means all text in status bars in WinForms applications is inaccessible to screen readers.

I have never had a problem retrieving the text of a label similar to what you describe. In fact the AutomationId is even the same in my application. The fact that ControlType is shown as ControlType.Edit is misleading. e.g. the following will work

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

Where automationElement has been located using a Find method against ControlType.Edit with an AutomationId of "StatusBar.Pane0".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top