Determining the Current Tab Page in Desktop Windows Applications

Applies to TestComplete 15.42, last modified on September 08, 2022

Each tabbed page of a tab control usually contains different sets of controls that allow you to perform certain actions. Therefore, you may need to determine which tabbed page is currently selected and perform some actions depending on this. Otherwise, your test may cause an error or perform actions over wrong controls.

While testing tab controls, you can use specific properties and methods of the corresponding program object to perform certain actions and obtain data stored in controls. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with the needed properties and methods from your scripts. However, when testing a control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

TestComplete uses Win32TabControl to get access to the properties and methods of Win32 tab controls. Actually, TestComplete associates Win32TabControl not only with standard Win32 tab controls, but also with all tab controls whose class names are listed in the Object Mapping options of the current project.

The wFocusedTab property of Win32TabControl returns the zero-based index of the currently selected tabbed page. The following sample code determines whether the fourth tab is focused. Then, if the specified tabbed page is focused, it sets focus to a certain check box and changes its state; otherwise, it first focuses the needed tab and then performs the mentioned actions.

JavaScript, JScript

function main()
{
var p, l, w, TabControl;

  // Open My Computer
  WshShell.Run("explorer.exe /e, /select,C:\\", SW_SHOWNORMAL);

  // Obtain the tab control
  p = Sys.Process("Explorer");
  l = p.Window("ExploreWClass", "My Computer", 1);
  l.Keys("~T[Up][Enter]");
  w = p.Window("#32770", "Folder Options", 1);
  TabControl = w.Window("SysTabControl32", "", 1);
  
  // Check whether the needed tabbed page is focused
  if (TabControl.wFocusedTab == 3)
  TabControl.Keys("[Tab][Tab][Tab][X32]");
  else
  TabControl.ClickTab(3);
  TabControl.Keys("[Tab][Tab][Tab][X32]");
}

Python

def Main():

  # Open My Computer
  WshShell.Run("explorer.exe /e, /select,C:\\", SW_SHOWNORMAL)

  # Obtain the tab control
  p = Sys.Process("Explorer")
  l = p.Window("ExploreWClass", "My Computer", 1) 
  l.Keys("~T[Up][Enter]")
  w = p.Window("#32770", "Folder Options", 1)
  TabControl = w.Window("SysTabControl32", "", 1)
  
  # Select tabs
  TabControl.Click(80,5)
  TabControl.Keys("[Right][Right]")
  TabControl.ClickTab(0)

VBScript

Sub main
Dim p, l, w, TabControl

  ' Open My Computer
  Call WshShell.Run("explorer.exe /e, /select,C:\", SW_SHOWNORMAL)

  ' Obtain the tab control
  Set p = Sys.Process("Explorer")
  Set l = p.Window("ExploreWClass", "My Computer", 1)
  l.Keys "~T[Up][Enter]"
  Set w = p.Window("#32770", "Folder Options", 1)
  Set TabControl = w.Window("SysTabControl32", "", 1)
  
  ' Check whether the needed tabbed page is focused
  If TabControl.wFocusedTab = 3 Then
  TabControl.Keys "[Tab][Tab][Tab][X32]"
  Else
  TabControl.ClickTab 3
  TabControl.Keys "[Tab][Tab][Tab][X32]"
  End If
End Sub

DelphiScript

procedure main();
var p, l, w, TabControl;
begin

  // Open My Computer
  WshShell.Run('explorer.exe /e, /select,C:\', SW_SHOWNORMAL);
  
  // Obtain the tab control
  p := Sys.Process('Explorer');
  l := p.Window('ExploreWClass', 'My Computer', 1);
  l.Keys('~T[Up][Enter]');
  w := p.Window('#32770', 'Folder Options', 1);
  TabControl := w.Window('SysTabControl32', '', 1);
  
  // Check whether the needed tabbed page is focused
  if (TabControl.wFocusedTab = 3)
  then
  TabControl.Keys('[Tab][Tab][Tab][X32]')
  else
  TabControl.ClickTab(3);
  TabControl.Keys('[Tab][Tab][Tab][X32]');
end;

C++Script, C#Script

function main()
{
var p, l, w, TabControl;

  // Open My Computer
  WshShell["Run"]("explorer.exe /e, /select,C:\\", SW_SHOWNORMAL);

  // Obtain the tab control
  p = Sys["Process"]("Explorer");
  l = p["Window"]("ExploreWClass", "My Computer", 1);
  l.Keys("~T[Up][Enter]");
  w = p["Window"]("#32770", "Folder Options", 1);
  TabControl = w["Window"]("SysTabControl32", "", 1);
  
  // Check whether the needed tabbed page is focused
  if (TabControl.wFocusedTab == 3)
  TabControl["Keys"]("[Tab][Tab][Tab][X32]");
  else
  {
  TabControl["ClickTab"](3);
  TabControl["Keys"]("[Tab][Tab][Tab][X32]");
  }
}

See Also

Working With Tab Controls in Desktop Windows Applications
wFocusedTab Property (Tab Controls)

Highlight search results