Determining the Number of Tab Pages in Desktop Windows Applications

Applies to TestComplete 15.40, last modified on July 05, 2022

Tab controls include a range of tabbed pages that provide different functionality. When working with a tab control, you may need to determine the number of tabs the tab control contains. You can count them, but if the number of tabbed pages is rather large, not all of the tabs can be shown at the same time. In this case, the tab control displays the UpDown control on the right of the tab area and the user can scroll to the needed tab by clicking the Up and Down buttons.

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.

During the test run TestComplete analyzes controls' class names and associates standard tab controls, listed in the Object Mapping project’s options, with the Win32TabControl object. You can use specific properties and methods of this object to perform various operations over the tested control.

You can determine the total number of tabs a tab control contains via the wTabCount property. The following sample code obtains the number of tabs and posts it to the test log:

JavaScript, JScript

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

  // 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);
  
  // Determine the number of tabs
  TabNumber = TabControl.wTabCount;
  Log.Message("Tab control contains " + TabNumber + " tab(s).");
}

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)
  
  # Determine the number of tabs
  TabNumber = TabControl.wTabCount
  Log.Message("Tab control contains " + TabNumber + " tab(s).")

VBScript

Sub main
Dim p, l, w, TabControl, TabNumber

  ' 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)
  
  ' Determine the number of tabs
  TabNumber = TabControl.wTabCount
  Log.Message("Tab control contains " & TabNumber& " tabs.")
End Sub

DelphiScript

procedure main();
var p, l, w, TabControl, TabNumber;
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);
  
  // Determine the number of tabs
  TabNumber := TabControl.wTabCount;
  Log.Message('Tab control contains ' + aqConvert.VarToStr(TabNumber) + ' tabs.');
end;

C++Script, C#Script

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

  // 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);
  
  // Determine the number of tabs
  TabNumber = TabControl["wTabCount"];
  Log["Message"]("Tab control contains " + TabNumber + " tabs.");
}

See Also

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

Highlight search results