For additional information on dynamic locator attributes, see Dynamic Locator Attributes.
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.
<Button Name="okButton" AutomationProperties.AutomationId="okButton" Click="okButton_Click">Ok</Button>