Determining the Current Tab Page

Applies to TestComplete 15.42, last modified on September 08, 2022
Determining the Selected Tab

To check which tab in a tab host control is currently selected, use the wFocusedTab property of the Android TabHost object that TestComplete associates with that control. This property returns the index number (zero-based) of the selected tab item. The following example checks if the first tab of the tab host control is selected, and if it is not, posts the number of the selected tab 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 the selected tab
  var Selected = TabHost.wFocusedTab + 1;
  
  // Check if the first tab is selected
  if (Selected == 1)
    // Post result to the log
    Log.Message("The first tab is selected");
  else
    Log.Message("The first tab is not selected. The selected tab is " + Selected);
}

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 the selected tab
  Selected = TabHost.wFocusedTab + 1
  
  # Check if the first tab is selected
  if (Selected == 1):
    # Post result to the log
    Log.Message("The first tab is selected")
  else:
    Log.Message("The first tab is not selected. The selected tab is " + str(Selected))

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 the selected tab
  Selected = IntToStr(TabHost.wFocusedTab + 1)
  
  ' Check if the first tab is selected
  If Selected = 1 Then
    ' Post result to the log
    Log.Message("The first tab is selected")
  Else
    Log.Message("The first tab is not selected. The selected tab is " + Selected)
  End If
End Sub

DelphiScript

procedure Test();
var
  p, TabHost, Selected : 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 the selected tab
  Selected := IntToStr(TabHost.wFocusedTab + 1);
  
  // Check if the first tab is selected
  if Selected = 1 then
    // Post result to the log
    Log.Message('The first tab is selected')
  else
    Log.Message('The first tab is not selected. The selected tab is ' + Selected);
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 the selected tab
  var Selected = TabHost["wFocusedTab"] + 1;
  
  // Check if the first tab is selected
  if (Selected == 1)
    // Post result to the log
    Log["Message"]("The first tab is selected");
  else
    Log["Message"]("The first tab is not selected. The selected tab is " + Selected);
}

Simulating Actions From Keyword Tests

This topic explains how to determine the selected tab of the tab host control in scripts. You can use the described method 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
wFocusedTab Property (Tab Controls)
Determining the Number of Tab Pages

Highlight search results