aqObject.CallMethod Method

Applies to TestComplete 15.45, last modified on December 01, 2022

Description

Use the CallMethod method to call the specified method of a certain object. If the method you want to call requires one or more parameters, they should be specified after the MethodName parameter.

Declaration

aqObject.CallMethod(IObject, MethodName, Param1, Param2, ...)

IObject [in]    Required    Object    
MethodName [in]    Required    String    
Param1 [in]    Optional    Variant    
Param2 [in]    Optional    Variant    
...
Result Variant

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

IObject

The object whose method you want to call.

MethodName

The name of the method to be called.

If the method with the given name is not found, an error occurs. Use the aqObject.IsSupported method to verify whether the object has a certain method.

Param1, Param2, ..., ParamN

Specify the parameters (if any) required by the method being called.

Result Value

If the MethodName method is a function, CallMethod returns its result value. Else, CallMethod returns a varEmpty Variant variable.

Remarks

To call a script routine by its name, use the Runner.CallMethod method.

Example

The code below launches notepad.exe from the list of tested applications, enters the Hello! string in the main window of Notepad and then closes the window without saving the file.

JavaScript, JScript

function CallObjectMethod()
{

  // Launches notepad.exe
  WshShell.Run("notepad.exe", SW_NORMAL);
  
  // Specifies the objects that correspond
  // to the notepad editor window and main window
  var Obj = Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1);
  var wndNotepad = Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1);
  
  // Enters the Hello! string in the main editor window
  aqObject.CallMethod(Obj, "Keys", "Hello!!");
  
  // Closes the notepad editor without saving the file
  aqObject.CallMethod(wndNotepad, "Close");
  
  // Specifies the object that corresponds to the NO button in the Save File dialog
  var btnNo = Sys.Process("notepad").Window("#32770", "Notepad", 1).Window("Button", "&No", 2);
  aqObject.CallMethod(btnNo, "ClickButton");
   
}

Python

def CallObjectMethod():
  # Launches notepad.exe
  WshShell.Run("notepad.exe", SW_NORMAL)
  # Specifies the objects that correspond
  # to the notepad editor window and main window
  Obj = Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1)
  wndNotepad = Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1)
  # Enters the Hello! string in the main editor window 
  aqObject.CallMethod(Obj, "Keys", "Hello!!")
  # Closes the notepad editor without saving the file
  aqObject.CallMethod(wndNotepad, "Close")
  # Specifies the object that corresponds to the NO button in the Save File dialog
  btnNo = Sys.Process("notepad").Window("#32770", "Notepad", 1).Window("Button", "&No", 2)
  aqObject.CallMethod(btnNo, "ClickButton")

VBScript

Sub CallObjectMethod

  ' Launches notepad.exe
  Call WshShell.Run("notepad.exe", SW_NORMAL)
  
  ' Specifies the objects that correspond
  ' to the notepad editor window and main window
  Set Obj = Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1)
  Set wndNotepad = Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1)
  
  ' Enters the Hello! string in the main editor window
  Call aqObject.CallMethod(Obj, "Keys", "Hello!!")
  
  ' Closes the notepad editor without saving the file
  Call aqObject.CallMethod(wndNotepad, "Close")
  
  ' Specifies the object that corresponds to the NO button in the Save File dialog
  Set btnNo = Sys.Process("notepad").Window("#32770", "Notepad", 1).Window("Button", "&No", 2)
  Call aqObject.CallMethod(btnNo, "ClickButton")
   
End Sub

DelphiScript

function CallObjectMethod;
var Obj, wndNotepad, btnNo;
begin

  // Launches notepad.exe
  WshShell.Run('notepad.exe', SW_NORMAL);
  
  // Specifies the objects that correspond
  // to the notepad editor window and main window
  Obj := Sys.Process('notepad').Window('Notepad', 'Untitled - Notepad', 1).Window('Edit', '', 1);
  wndNotepad := Sys.Process('notepad').Window('Notepad', 'Untitled - Notepad', 1);
  
  // Enters the Hello! string in the main editor window
  aqObject.CallMethod(Obj, 'Keys', 'Hello!!');
  
  // Closes the notepad editor without saving the file
  aqObject.CallMethod(wndNotepad, 'Close');
  
  // Specifies the object that corresponds to the NO button in the Save File dialog
  btnNo := Sys.Process('notepad').Window('#32770', 'Notepad', 1).Window('Button', '&No', 2);
  aqObject.CallMethod(btnNo, 'ClickButton');
   
end;

C++Script, C#Script

function CallObjectMethod()
{

  // Launches notepad.exe
  WshShell["Run"]("notepad.exe", SW_NORMAL);;
  
  // Specifies the objects that correspond
  // to the notepad editor window and main window
  var Obj = Sys["Process"]("notepad")["Window"]("Notepad", "Untitled - Notepad", 1)["Window"]("Edit", "", 1);
  var wndNotepad = Sys["Process"]("notepad")["Window"]("Notepad", "Untitled - Notepad", 1);
  
  // Enters the Hello! string in the main editor window
  aqObject["CallMethod"](Obj, "Keys", "Hello!!");
  
  // Closes the notepad editor without saving the file
  aqObject["CallMethod"](wndNotepad, "Close");
  
  // Specifies the object that corresponds to the NO button in the Save File dialog
  var btnNo = Sys["Process"]("notepad")["Window"]("#32770", "Notepad", 1)["Window"]("Button", "&No", 2);
  aqObject["CallMethod"](btnNo, "ClickButton");
   
}

See Also

GetPropertyValue Method
SetPropertyValue Method
RaiseEvent Method
IsSupported Method
CallMethod Method

Highlight search results