Selecting Tab Pages

Applies to TestComplete 14.10, last modified on June 5, 2019

Tab controls usually have several tabbed pages that contain a set of other controls, which allows you to retrieve data, set options and so on. When testing a tab control, you may need to perform various actions over the controls the tested tab control contains. Before working with the controls that belong to a certain tabbed page, you should select the corresponding tab.

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 the control's class names and associates standard tab controls with the Win32TabControl object (see Object Mapping). This object provides access to internal properties and methods of the tested tab control.

You can select the specified tabbed page by clicking on its tab (see Click). In this case, you need to estimate the coordinates of the corresponding tab. This approach is inconvenient if the tab control does not show all of the tabs, because first, you should scroll to the needed tab and then simulate a click. So, the coordinates of the tabs will depend on scrolling.

Another way to select it is to set focus to the tab control and select the needed tab via the [Left] and [Right] shortcuts. In this case, you should navigate through the successive items until you select the needed one. You can use the Keys action to simulate keystrokes.

The above-mentioned approaches of selecting tabbed pages are similar to those that you can perform manually. However, when working with a tab control from tests, it is more convenient to select the needed page by using the ClickTab action provided by Win32TabControl. This action clicks on the needed tab item specified by its index or caption.

Note that it is possible to use wildcards (* and ?) or regular expressions to specify a tab item caption. An asterisk (*) corresponds to a string of any length (including an empty string), a question mark corresponds to any single character (including none). If you wish to specify an asterisk (*) as part of a tab item caption, you should double it, because otherwise, it will be treated as a wildcard. To specify more complicated parts of a caption, use regular expressions. Here is an example of how to select any tab item:

TabControlObj.ClickTab("*")

The following example demonstrates how to select tab items using the above-mentioned approaches:

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);
  
  // Select tabs
  TabControl.Click(80,5);
  TabControl.Keys("[Right][Right]");
  TabControl.ClickTab(0);
}

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)
  
  ' Select tabs
  TabControl.Click 80,5
  TabControl.Keys "[Right][Right]"
  TabControl.ClickTab(0)
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);
  
  //Select tabs
  TabControl.Click(80,5);
  TabControl.Keys('[Right][Right]');
  TabControl.ClickTab(0);
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);
  
  //Select tabs
  TabControl["Click"](80,5);
  TabControl["Keys"]("[Right][Right]");
  TabControl["ClickTab"](0);
}

See Also

Working With Tab Controls
ClickTab Action (Tab Controls)
Click Action
Keys Action

Highlight search results