views:

449

answers:

1

I'm trying to set up UI automation for Silverlight 3. I have a little test project that has 2 elements, a Button and a TextBlock. When you click the button the text is supposed to change.

I have been able to simulate a button click and the text does correctly change on the UI. However I am having problems retrieving the text from the TextBlock. UISpy shows that it is of type "text" but it also shows that it implements no control patterns. If I use a TextBox I can get the text correctly using a ValuePattern, but I would prefer to use TextBlock.

Does anyone know how to get the current text of a TextBlock from it's AutomationElement object?

A: 

TextBlock exposes its text as the Name property of the automation element, so you can read the text from myTextBlockAutomationElement.Current.Name.

GraemeF
TextBlock does show up in the control view. I have no problem getting the AutomationElement but from there I can not get at the text. With a TextBox you can check the ValuePattern and get it's text but that doesn't work with a TextBlock. What I need is a way to get the actual text from a TextBlock.
Stephan
Sorry - I was writing from memory. I'll check how I've actually done it. :)
GraemeF
Is that what you were looking for?
GraemeF
Yeah that's exactly it. I actually just found that. The caveat I'll specify is that you can't supply a name property. You must identify items using AutomationProperties.AutomationId and not AutomationProperties.Name. As long as it doesn't have a name it will work great. Thanks for your help.
Stephan

related questions