Determining the Number of Tab Pages

Applies to TestComplete 14.81, last modified on May 04, 2021
Getting wTabCount Property

To determine the total number of tabs, use the wTabCount property of the Android TabHost object that TestComplete automatically associates with your tab host control. This property returns the total number of tabs in the tab host control. The following example obtains the number of tabs in a control and posts it to the log:

JavaScript, JScript

function Test()
{
  // Select the Android device
  Mobile.SetCurrent("MyDevice");

  // Obtain the TabHost object
  var p = Mobile.Device().Process("com.example.myapp");
  var TabHost = p.RootLayout("").Layout("layoutTop").TabHost("tabhost");
  
  // Get the number of tabs
  var TabCount = TabHost.wTabCount;
  
  // Post the number to the log
  Log.Message("The number of tabs is " + TabCount);
}

Python

def Test():
  # Select the Android device
  Mobile.SetCurrent("MyDevice")

  # Obtain the TabHost object
  p = Mobile.Device().Process("com.example.myapp")
  TabHost = p.RootLayout("").Layout("layoutTop").TabHost("tabhost")
  
  # Get the number of tabs
  TabCount = TabHost.wTabCount
  
  # Post the number to the log
  Log.Message("The number of tabs is " + TabCount)

VBScript

Sub Test()
  Dim p, TabHost

  ' Select the Android device
  Mobile.SetCurrent("MyDevice")

  ' Obtain the TabHost object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set TabHost = p.RootLayout("").Layout("layoutTop").TabHost("tabhost")
  
  ' Get the number of tabs
  TabCount = IntToStr(TabHost.wTabCount)
  
  ' Post the number to the log
  Log.Message("The number of tabs is " + TabCount)
End Sub

DelphiScript

procedure Test();
var
  p, TabHost, TabCount : OleVariant;
begin
  // Select the Android device
  Mobile.SetCurrent('MyDevice');

  // Obtain the TabHost object
  p := Mobile.Device.Process('com.example.myapp');
  TabHost := p.RootLayout('').Layout('layoutTop').TabHost('tabhost');
  
  // Get the number of tabs
  TabCount := IntToStr(TabHost.wTabCount);
  
  // Post the number to the log
  Log.Message('The number of tabs is ' + TabCount);
end;

C++Script, C#Script

function Test()
{
  // Select the Android device
  Mobile["SetCurrent"]("MyDevice");

  // Obtain the TabHost object
  var p = Mobile["Device"].Process("com.example.myapp");
  var TabHost = p["RootLayout"]("")["Layout"]("layoutTop")["TabHost"]("tabhost");
  
  // Get the number of tabs
  var TabCount = TabHost["wTabCount"];
  
  // Post the number to the log
  Log["Message"]("The number of tabs is " + TabCount);
}

Simulating Actions From Keyword Tests

This topic explains how to obtain the total number of tabs in the tab host control in scripts. You can use the described property in keyword tests too. To do this, use the On-Screen Action or the Call Object Method operations.

See Also

Working With Android Tab Host Controls
wTabCount Property (Tab Controls)
Selecting Tab Pages

Highlight search results