WPFObject Method

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

Use this method to obtain a scripting interface to the specified window or control of a WPF application. The resulting object contains methods and properties defined in the application code as well as methods, properties and actions provided by TestComplete.

Declaration

TestObj.WPFObject(Name)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
Name [in]    Required    String    
Result Object

TestObj.WPFObject(ClassName, WndCaption)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
ClassName [in]    Required    String    
WndCaption [in]    Required    String    
Result Object

TestObj.WPFObject(ClassName, WndCaption, Index)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
ClassName [in]    Required    String    
WndCaption [in]    Required    String    
Index [in]    Required    Integer    
Result Object

Applies To

The method is applied to the following objects:

View Mode

To view this method in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Parameters

The method has the following parameters:

Name

The name of the desired object as it is specified by the developers in the application’s source code. This is the value of the object’s WPFControlName property.

If the name is unavailable by some reason (for example, the application developers did not specify it), use the second implementation of the method to address the desired object.

ClassName

The window’s class name is specified by the application source code (not by the operating system’s class name). You should specify a short class name, for instance, Button, rather than System.Windows.Forms.Button. You can use wildcards (* and ?) in this parameter.

Note that WPF applications rely on helper substrate windows. These windows are .NET objects of the HWNDSource class created automatically during the application run. To address WPF application forms, use the following notation of the class name: substrate_window_class:form_name. For example, "HwndSource: MainForm".

WndCaption

Text of the desired onscreen object. If the object is a window, this text normally coincides with the window title. You can use wildcards (* and ?) in this parameter.

Index

Index of the window in the collection of child windows of the TestObj object.

The Index parameter is used only if an object contains two or more child objects that have the same class name and caption. It is used to distinguish these objects from each other. The first found object has an index of 1, the second -  2 and so on.
If there is only one child object with the specified class name and caption, index should not be specified. To decide whether the index should be used, explore your application in the Object Browser panel and use the naming format that is used by the panel.

Result Value

The WPFObject method returns an object that provides a scripting interface to an object located in a WPF application. If TestComplete cannot access the specified object (for example, this object does not exist), WPFObject will return an empty stub object and post an error message to the test log. To determine whether WPFObject returns a valid object, use the Exists property of the resultant object. If Exists returns False, then the returned object is a stub object and the call to WPFObject was not successful.

Remarks

If you only use one parameter, TestComplete considers the use of the first WPFObject method implementation and the parameter as the object’s name. If you use two or three parameters, TestComplete considers it as using the second and third implementation correspondingly.

The Object Browser’s tree only displays those WPF objects that are descendants of the FrameworkElement or FrameworkContentElement class. So, you can only use the WPFObject method to obtain these objects.

The object returned by the WPFObject method contains methods and properties defined in the application code as well as methods, properties and actions provided by TestComplete. The returned object may hold two or more methods and properties having the same name. If you call such a method or property, a naming conflict will occur. To avoid this and to specify which method or property is to be called, use the NativeClrObject namespace.

The WPFObject method is available only if the WPF Control Support plugin is installed and enabled in File | Install Extensions. Otherwise, the method is absent in the method list of the TestObj object.
If the plugin is installed, you cannot use the Window method to address windows of your WPF application, you should use WPFObject instead.

Example

To view an example that demonstrates how to use the WPFObject method, see Addressing Objects in WPF Applications.

See Also

WaitWPFObject Method
Addressing Objects in WPF Applications
Object Browser Naming Notation

Highlight search results