Getting a Toggle Button Control's Text

Applies to TestComplete 15.68, last modified on October 16, 2024
Getting Native Fields

To determine the text of a switch in the current state, use the native mText field. This field returns the current text of the control. To determine the text of a control in the "on" and "off" states, use the mTextOn and mTextOff fields. These fields can be used in the same way as properties provided by TestComplete. The following example determines the text of the toggle button control and posts it to the log:

JavaScript, JScript

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

  // Obtain the required ToggleButton
  var p = Mobile.Device().Process("com.example.myapp");
  var Toggle = p.RootLayout("").Layout("layoutTop").Layout("layout1").ToggleButton("toggle1");
  
  // Obtain the text of ToggleButton
  var Text = Toggle.mText;
  
  // Post the text to the log
  Log.Message(Text);
}

Python

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

  # Obtain the required ToggleButton
  p = Mobile.Device().Process("com.example.myapp")
  Toggle = p.RootLayout("").Layout("layoutTop").Layout("layout1").ToggleButton("toggle1")
  
  # Obtain the text of ToggleButton
  Text = Toggle.mText
  
  # Post the text to the log
  Log.Message(Text)

VBScript

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

  ' Obtain the required ToggleButton
  Set p = Mobile.Device.Process("com.example.myapp")
  Set Toggle = p.RootLayout("").Layout("layoutTop").Layout("layout1").ToggleButton("toggle1")
  
  ' Obtain the text of ToggleButton
  Text = Toggle.mText
  
  ' Post the text to the log
  Call Log.Message(Text)
End Sub

DelphiScript

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

  // Obtain the required ToggleButton
  p := Mobile.Device.Process('com.example.myapp');
  Toggle := p.RootLayout('').Layout('layoutTop').Layout('layout1').ToggleButton('toggle1');
  
  // Obtain the text of ToggleButton
  Text := Toggle.mText;
  
  // Post the text to the log
  Log.Message(Text);
end;

C++Script, C#Script

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

  // Obtain the required ToggleButton
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var Toggle = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1")["ToggleButton"]("toggle1");
  
  // Obtain the text of ToggleButton
  var Text = Toggle["mText"];
  
  // Post the text to the log
  Log["Message"](Text);
}

Simulating Actions From Keyword Tests

This topic explains how to get the text of the toggle button control in scripts. You can use the described fields in keyword tests too. To do this, use the On-Screen Action or the Call Object Method operations.

See Also

Working With Android Toggle Button Controls
Determining a Toggle Button's State
Changing Toggle Button State

Highlight search results