Fetching Property of a Silverlight control

In Coded UI Test you can fetch the property of a control using two approaches –


1. Use the properties exposed in the Specialized Class.

    E.g. SilverlightList.SelectedItems returns the selected items in the list box.


2. Use the UITestControl.GetProperty() API.

    E.g. SilverlightList.GetProperty(SilverlightControl.PropertyNames.SelectedItems) as string[].

    This API can be used to fetch any property supported by that control with the limitation that the property value needs to be serializable.  For example, if you try to do a GetProperty(“Cursor”) on a SilverlightButton control, it will throw a NotSupportedException. 




As indicated in the error snapshot above, there is an additional 3rd API introduced specifically for Silverlight Controls, GetPropertyAsString() which can be used to get the string representation of the property value. This simply returns the .ToString() value returned for that property value. Beyond that, there is no specific heuristics on per property or control basis implemented within. 



Why is a specialized class property GET throwing NotSupportedException?


Say you located an control using the Coded UI Test control locator and added it to UIMap. Coded UI Test generated an specialized class for that control. Using intellisense, you figured out the supported properties and tried get a property, for example, SilverlightComboBox.SelectedItem. Instead, when you run the test, it throws NotSupportedException.


If you come across this scenario, it implies that it is a custom control having the same Control Type as the one supported by that Specialized Class. Note that Coded UI Test determines the Specialized Class based on the control type information. If the custom control’s UIElement and/or its Automation Peer returns the control type string as that of the specialized class’s supported control type, Coded UI Test will generate a specialized control class for it.


In such a scenario, you would need to figure out the exact properties supported by that custom control and use GetProperty or GetPropertyAsString APIs (depending on whether the property is serializable or not) to fetch the required property value.


Comments (2)

  1. Seetal says:

    SilverlightList sl = new SilverlightList();

    If I now type:


    'SelectedItems' is underlined in red for a missing definition.

    If I type:


    There are no errors.

    By reading this blog, I am confused what is the correct way to fetch properties of Silverlight Controls.

  2. SelectedItems is a property of SilverlightList. It is a control specific property. SilverlightControl.PropertyNames will give all the generic silverlight control properties such as Name, AutomationId, etc.

Skip to main content