Selecting Tab Pages

Applies to TestComplete 15.63, last modified on April 23, 2024
Simulating TouchTab Action

To select a tab, use the TouchTab or LongTouchTab actions. These actions simulate a single short or long touch on the tab specified by its index (starting from 0) or caption. If the tab is already selected, no actions are performed. The following example selects the first tab of the tab host control and then selects a different tab with the "Tab2" caption:

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");
  
  // Select the tab by the index
  TabHost.TouchTab(0);
  
  // Select the tab by its text
  TabHost.TouchTab("Tab2");
}

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")
  
  # Select the tab by the index
  TabHost.TouchTab(0)
  
  # Select the tab by its text
  TabHost.TouchTab("Tab2")

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")
  
  ' Select the tab by the index
  TabHost.TouchTab(0)
  
  ' Select the tab by its text
  TabHost.TouchTab("Tab2")
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');
  
  // Select the tab by the index
  TabHost.TouchTab(0);
  
  // Select the tab by its text
  TabHost.TouchTab('Tab2');
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");
  
  // Select the tab by the index
  TabHost["TouchTab"](0);
  
  // Select the tab by its text
  TabHost["TouchTab"]("Tab2");
}

Note: When performing a touch using tab caption, you can use wildcards (* and ?) or regular expressions. The wildcard asterisk (*) corresponds to a string of any length (including an empty string), the wildcard question mark corresponds to any single character (including none). To specify more complicated parts of a caption, use regular expressions.
Simulating Actions From Keyword Tests

This topic explains how to simulate selecting tabs of the tab host control in scripts. You can use the described methods 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
Determining the Current Tab Page
TouchTab Method (Mobile Controls)
LongTouchTab Method (Specific to Android TabHost Controls)

Highlight search results