Getting Tab Pages' Captions in Desktop Windows Applications

Applies to TestComplete 15.47, last modified on January 20, 2023

Each tabbed page of a tab control has a caption that usually describes the functionality of the controls that are placed on this page. You may need to obtain such a caption to use it in your scripts.

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 associates Win32TabControl with standard tab controls, so you can use specific properties and methods provided by this object to obtain data and perform various operations over the tested tab control. The wTabCaption allows you to obtain the caption of the tabbed page specified by its index. If the specified tab does not exist, the wTabCaption property returns an empty string and posts an error message to the log.

Here is a sample code that obtains all of the tab captions of a tab control and posts them to the test log:

JavaScript, JScript

function main()
{
var p, l, w, i, 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;
    
  // Obtain tab captions and post them to the test log
  for (i = 0; i < TabNumber; i++)
     Log.Message(TabControl.wTabCaption(i))
}

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
    
  # Obtain tab captions and post them to the test log
  for i in range(0, TabNumber-1):
     Log.Message(TabControl.wTabCaption[i])

VBScript

Sub main
Dim p, l, w, i, 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
    
  ' Obtain tab captions and post them to the test log
   For i = 0 To TabNumber-1
     Log.Message(TabControl.wTabCaption(i))
   Next 
End Sub

DelphiScript

procedure Main();
var p, l, w, i, 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;

   // Obtain tab captions and post them to the test log
   For i := 0 To TabNumber-1 do
     Log.Message(TabControl.wTabCaption(i))
end;

C++Script, C#Script

function main()
{
var p, l, w, i, 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"];
  
  // Obtain tab captions and post them to the test log
  for (i = 0; i < TabNumber; i++)
  Log.Message(TabControl.wTabCaption(i))
}

See Also

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

Highlight search results