SetFocus Method (BrowserWindow and Window Objects)

Applies to TestComplete 15.48, last modified on March 01, 2023

Description

This action moves the input focus to the given object. If the object cannot obtain the input focus, the method fails and posts an error message to the test log.

Declaration

TestObj.SetFocus()

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
Result None

Applies To

The method is applied to the following objects:

View Mode

This method is available in the Object Browser panel and in other panels and dialogs in both Basic and Advanced view modes.

Result Value

None.

Example

The following example demonstrates how to use the SetFocus method in scripts:

JavaScript, JScript

var w = Sys.Process("notepad").Window("Notepad", "*", 1);
w.Activate();
w.Minimize();
w.Restore();
w.Position(10, 10, 450, 250);
w.Maximize();
w.Restore();
w.SetFocus();

Python

w = Sys.Process("notepad").Window("Notepad", "*", 1)
w.Activate()
w.Minimize()
w.Restore()
w.Position(10, 10, 450, 250)
w.Maximize()
w.Restore()
w.SetFocus()

VBScript

Set w = Sys.Process("notepad").Window("Notepad", "*", 1)
w.Minimize
w.Restore
w.Activate
w.Minimize
w.Restore
Call w.Position(10, 10, 450, 250)
w.Maximize
w.Restore
w.SetFocus

DelphiScript

var w;
begin
  w := Sys.Process('notepad').Window('Notepad', '*', 1);
  w.Activate;
  w.Minimize;
  w.Restore;
  w.Position(10, 10, 450, 250);
  w.Maximize;
  w.Restore;
  w.SetFocus;

end;

C++Script, C#Script

var w = Sys["Process"]("notepad")["Window"]("Notepad","*", 1);
w["Activate"]();
w["Minimize"]();
w["Restore"]();
w["Position"](10, 10, 450, 250);
w["Maximize"]();
w["Restore"]();
w["SetFocus"]();

See Also

Focused Property
Enabled Property
Visible Property
Activate Action
Restore Action

Highlight search results