Getting Switch Control's Text

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

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

JavaScript, JScript

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

  // Obtain the required switch
  var p = Mobile.Device().Process("com.example.myapp");
  var Swtch = p.RootLayout("").Layout("layoutTop").Layout("layout2").Switch("switch1");
  
  // Obtain the text of the switch in the "on" state
  var Text = Swtch.mTextOn;
  
  // Post the text to the log
  Log.Message(Text);
}

Python

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

  # Obtain the required switch
  p = Mobile.Device().Process("com.example.myapp")
  Swtch = p.RootLayout("").Layout("layoutTop").Layout("layout2").Switch("switch1")
  
  # Obtain the text of the switch in the "on" state
  Text = Swtch.mTextOn
  
  # Post the text to the log
  Log.Message(Text)

VBScript

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

  ' Obtain the required switch
  Set p = Mobile.Device.Process("com.example.myapp")
  Set Swtch = p.RootLayout("").Layout("layoutTop").Layout("layout2").Switch("switch1")
  
  ' Obtain the text of the switch in the "on" state
  Set Text = Swtch.mTextOn
  
  ' Post the text to the log
  Call Log.Message(Text)
End Sub

DelphiScript

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

  // Obtain the required switch
  p := Mobile.Device.Process('com.example.myapp');
  Swtch := p.RootLayout('').Layout('layoutTop').Layout('layout2').Switch('switch1');
  
  // Obtain the text of the switch in the "on" state
  Text := Swtch.mTextOn;
  
  // 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 switch
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var Swtch = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout2")["Switch"]("switch1");
  
  // Obtain the text of the switch in the "on" state
  var Text = Swtch["mTextOn"];
  
  // Post the text to the log
  Log["Message"](Text);
}

Simulating Actions From Keyword Tests

This topic explains how to get the text of the switch 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 Switch Controls
Changing Switch State
Determining a Switch's State

Highlight search results