Attributes for Windows Presentation Foundation (WPF) Applications

Supported attributes for WPF applications include:
  • automationId
  • caption
  • className
  • name
  • All dynamic locator attributes.
Note: Attribute names are case sensitive, except for mobile applications, where the attribute names are case insensitive. Attribute values are by default case insensitive, but you can change the default setting like any other option. The locator attributes support the wildcards ? and *.

For additional information on dynamic locator attributes, see Dynamic Locator Attributes.

Object Recognition

To identify components within WPF scripts, you can specify the automationId, caption, className, or name. The name that is given to an element in the application is used as the automationId attribute for the locator if available. As a result, most objects can be uniquely identified using only this attribute. For example, a locator with an automationId might look like: //WPFButton[@automationId='okButton']".

If you define an automationId and any other attribute, only the automationId is used during replay. If there is no automationId defined, the name is used to resolve the component. If neither a name nor an automationId are defined, the caption value is used. If no caption is defined, the className is used. We recommend using the automationId because it is the most useful property.

Attribute Type Description Example
automationId

An ID that was provided by the developer of the test application.

//WPFButton[@automationId='okButton']"
name The name of a control. The Visual Studio designer automatically assigns a name to every control that is created with the designer. The application developer uses this name to identify the control in the application code.
//WPFButton[@name='okButton']"
caption

The text that the control displays. When testing a localized application in multiple languages, use the automationId or name attribute instead of the caption.

//WPFButton[@automationId='Ok']"
className

The simple .NET class name (without namespace) of the WPF control. Using the class name attribute can help to identify a custom control that is derived from a standard WPF control that Silk4J recognizes.

//WPFButton[@className='MyCustomButton']"

During recording, Silk4J creates a locator for a WPF control by using the automationId, name, caption, or className attributes in the order that they are listed in the preceding table. For example, if a control has a automationId and a name, Silk4J uses the automationId when creating the locator.

The following example shows how an application developer can define a name and an automationId for a WPF button in the XAML code of the application:
<Button Name="okButton" AutomationProperties.AutomationId="okButton"
Click="okButton_Click">Ok</Button>