Getting Tab Pages' Captions

Applies to TestComplete 15.40, last modified on July 05, 2022
Getting wTabText Property

To obtain the caption of a tab in a tab host control, use the wTabText property of the Android TabHost object that TestComplete associates with that control. This property returns the caption of the tab specified by its index (zero-based). The following example determines the caption of the first tab in some tab host control and posts it to the test 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 text of the first tab
  var TabText = TabHost.wTabText(0);
  
  // Post it to the log
  Log.Message(TabText);
}

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 text of the first tab
  TabText = TabHost.wTabText[0]
  
  # Post it to the log
  Log.Message(TabText)

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 text of the first tab
  TabText = TabHost.wTabText(0)
  
  ' Post it to the log
  Log.Message(TabText)
End Sub

DelphiScript

procedure Test();
var
  p, TabHost, TabText : 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 text of the first tab
  TabText := TabHost.wTabText(0);
  
  // Post it to the log
  Log.Message(TabText);
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 text of the first tab
  var TabText = TabHost["wTabText"](0);
  
  // Post it to the log
  Log["Message"](TabText);
}

Simulating Actions From Keyword Tests

This topic explains how to get the caption of the tab from 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
Enabled Property
Selecting Tab Pages

Highlight search results