 Getting the Number of Radio Buttons in RadioGroup
Getting the Number of Radio Buttons in RadioGroup
 Getting the Selected RadioButton
Getting the Selected RadioButton
Getting the Number of Radio Buttons in RadioGroup
To get the number of radio buttons contained in a radio group, use the wItemCount property of the Android RadioGroup object that TestComplete associates with that control. The following example posts the number of radio buttons in radio group to the log:
JavaScript, JScript
function Test()
						{
  // Select the Android device
  Mobile.SetCurrent("MyDevice");
  // Obtain the RadioGroup object
  var p = Mobile.Device().Process("com.example.myapp");
  var l = p.RootLayout("").Layout("layoutTop").Layout("layout1");
  var Radio =  l.RadioGroup("radiogroup1");   
   
  // Get the number of radio buttons   
  Items = Radio.wItemCount;
  
  // Post the number to the log
  Log.Message(Items);
						}
Python
def Test():
  # Select the Android device
  Mobile.SetCurrent("MyDevice")
  # Obtain the RadioGroup object
  p = Mobile.Device().Process("com.example.myapp")
  l = p.RootLayout("").Layout("layoutTop").Layout("layout1")
  Radio = l.RadioGroup("radiogroup1")
   
  # Get the number of radio buttons 
  Items = Radio.wItemCount
  
  # Post the number to the log
  Log.Message(Items)VBScript
Sub Test()
  ' Select the Android device
  Mobile.SetCurrent("MyDevice")
  ' Obtain the RadioGroup object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set l = p.RootLayout("").Layout("layoutTop").Layout("layout1")
  Set Radio =  l.RadioGroup("radiogroup1")
  ' Get the number of radio buttons   
  Items = Radio.wItemCount
  
  ' Post the number to the log
  Log.Message(Items)
End Sub
DelphiScript
procedure Test();
var
  p, l, Items, Radio : OleVariant;
begin
  // Select the Android device
  Mobile.SetCurrent('MyDevice');
  // Obtain the RadioGroup object
  p := Mobile.Device.Process('com.example.myapp');
  l := p.RootLayout('').Layout('layoutTop').Layout('layout1');
  Radio :=  l.RadioGroup('radiogroup1'); 
  
  // Get the number of radio buttons 
  Items := Radio.wItemCount;
  
  // Post the number to the log
  Log.Message(Items);
end;
C++Script, C#Script
function Test()
						{
  // Select the Android device
  Mobile["SetCurrent"]("MyDevice");
  // Obtain the RadioGroup object
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var l = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1");
  var Radio = l["RadioGroup"]("radiogroup1");
  
  // Get the number of radio buttons 
  var Items = Radio["wItemCount"]();
  
  // Post the number to the log
  Log["Message"](Items);
						}
Getting the Selected RadioButton
To check which item is currently selected, use the 
		wSelectedItem property. This property returns the index number of the selected item (starting from 0). The following example checks whether the first button of the radio group is selected:
JavaScript, JScript
function Test()
						{
  // Select the Android device
  Mobile.SetCurrent("MyDevice");
  // Obtain the RadioGroup object
  var p = Mobile.Device().Process("com.example.myapp");
  var l = p.RootLayout("").Layout("layoutTop").Layout("layout1");
  var Radio =  l.RadioGroup("radiogroup1");
   
  // Check if RadioButton is checked
  if (Radio.wSelectedItem == 0)
    // Post the message to the log
    Log.Message("This option is selected");
  else
    Log.Message("This option is not selected");
						}
Python
def Test():
  # Select the Android device
  Mobile.SetCurrent("MyDevice")
  # Obtain the RadioGroup object
  p = Mobile.Device().Process("com.example.myapp")
  l = p.RootLayout("").Layout("layoutTop").Layout("layout1")
  Radio = l.RadioGroup("radiogroup1")
   
  # Check if RadioButton is checked
  if (Radio.wSelectedItem == 0):
    # Post the message to the log
    Log.Message("This option is selected")
  else:
    Log.Message("This option is not selected")VBScript
Sub Test()
  ' Select the Android device
  Mobile.SetCurrent("MyDevice")
  ' Obtain the RadioGroup object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set l = p.RootLayout("").Layout("layoutTop").Layout("layout1")
  Set Radio =  l.RadioGroup("radiogroup1")
  ' Check if RadioButton is checked
  If Radio.wSelectedItem = 0 Then
    ' Post the message to the log
    Log.Message "This option is selected"
  Else
    Log.Message "This option is not selected"
  End If
End Sub
DelphiScript
procedure Test();
var
  p, l, TextClock, Radio : OleVariant;
begin
  // Select the Android device
  Mobile.SetCurrent('MyDevice');
  // Obtain the RadioGroup object
  p := Mobile.Device.Process('com.example.myapp');
  l := p.RootLayout('').Layout('layoutTop').Layout('layout1');
  Radio :=  l.RadioGroup('radiogroup1'); 
  
  // Check if RadioButton is checked
  if Radio.wSelectedItem = 0 then
    // Post the message to the log
    Log.Message('This option is selected')
  else
    Log.Message('This option is not selected')
end;
C++Script, C#Script
function Test()
						{
  // Select the Android device
  Mobile["SetCurrent"]("MyDevice");
  // Obtain the RadioGroup object
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var l = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1");
  var Radio = l["RadioGroup"]("radiogroup1");
   
  // Check if RadioButton is checked
  if (Radio["wSelectedItem"] == 0)
    // Post the message to the log
    Log["Message"]("This option is selected");
  else
    Log["Message"]("This option is not selected");
						}
Simulating Touch Over the RadioGroup Item
To touch the specific item of a radio group, use the TouchItem or LongTouchItem actions. These actions perform the touch over the item, specified by its index (zero-based). If the selected item has the same index, no actions are performed. The following example touches the first radio button of the radio group:
JavaScript, JScript
function Test()
						{
  // Select the Android device
  Mobile.SetCurrent("MyDevice");
  // Obtain the RadioGroup object
  var p = Mobile.Device().Process("com.example.myapp");
  var l = p.RootLayout("").Layout("layoutTop").Layout("layout1");
  var Radio =  l.RadioGroup("radiogroup1");   
  
  // Touch RadioButton
  Radio.TouchItem(0);
						}
Python
def Test():
  # Select the Android device
  Mobile.SetCurrent("MyDevice")
  # Obtain the RadioGroup object
  p = Mobile.Device().Process("com.example.myapp")
  l = p.RootLayout("").Layout("layoutTop").Layout("layout1")
  Radio = l.RadioGroup("radiogroup1")
  
  # Touch RadioButton
  Radio.TouchItem(0)VBScript
Sub Test()
  ' Select the Android device
  Mobile.SetCurrent("MyDevice")
  ' Obtain the RadioGroup object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set l = p.RootLayout("").Layout("layoutTop").Layout("layout1")
  Set Radio =  l.RadioGroup("radiogroup1")
  ' Touch the clock
  Radio.TouchItem(0)
End Sub
DelphiScript
procedure Test();
var  p, l, TextClock, Radio : OleVariant;
begin
  // Select the Android device
  Mobile.SetCurrent('MyDevice');
  // Obtain the RadioGroup object
  p := Mobile.Device.Process('com.example.myapp');
  l := p.RootLayout('').Layout('layoutTop').Layout('layout1');
  Radio :=  l.RadioGroup('radiogroup1'); 
  
  // Touch RadioButton
  Radio.TouchItem(0);
end;
C++Script, C#Script
function Test()
						{
  // Select the Android device
  Mobile["SetCurrent"]("MyDevice");
  // Obtain the RadioGroup object
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var l = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1");
  var Radio = l["RadioGroup"]("radiogroup1");
  
  // Touch RadioButton
  Radio["TouchItem"](0); 
						}
Getting RadioButton Caption
You can obtain the caption of any button specified by its index by using the wItem property. The following code snippet demonstrates how to get a button’s caption:
JavaScript, JScript
function Test()
{
  // Select an Android device
  Mobile.SetCurrent("MyDevice");
  // Obtain a radio group
  var app = Mobile.Device().Process("com.example.myapp");
  var radiogroupObj = app.RootLayout("").Layout("layout1").RadioGroup("radiogroup1");
 
  // Obtain the caption of the first item and post it to the test log
  var text = radiogroupObj.wItem(0);
  Log.Message(text);
}
Python
def Test():
  # Select the Android device
  Mobile.SetCurrent("MyDevice")
  # Obtain the radio group
  app = Mobile.Device().Process("com.example.myapp")
  radiogroupObj = app.RootLayout("").Layout("layout1").RadioGroup("radiogroup1")
 
  # Obtain the caption of the first item and post it to the test log
  text = radiogroupObj.wItem[0]
  Log.Message(text)VBScript
Sub Test() 
  Dim app, radiogroupObj, text
  ' Select an Android device
  Mobile.SetCurrent("MyDevice")
  ' Obtain a radio group
  Set app = Mobile.Device.Process("com.example.myapp")
  Set radiogroupObj = app.RootLayout("").Layout("layout1").RadioGroup("radiogroup1")
 
  ' Obtain the caption of the first item and post it to the test log
  text = radiogroupObj.wItem(0)
  Log.Message(text)
End Sub
DelphiScript
procedure Test();
var app, radiogroupObj, text: OleVariant;
begin
  // Select an Android device
  Mobile.SetCurrent('MyDevice');
  // Obtain a radio group
  app := Mobile.Device.Process('com.example.myapp');
  radiogroupObj := app.RootLayout('').Layout('layout1').RadioGroup('radiogroup1');
 
  // Obtain the caption of the first item and post it to the test log
  text := radiogroupObj.wItem(0);
  Log.Message(text);
end;
C++Script, C#Script
function Test() 
{
  // Select an Android device
  Mobile["SetCurrent"]("MyDevice");
  // Obtain a radio group
  var app = Mobile["Device"]["Process"]("com.example.myapp");
  var radiogroupObj = app["RootLayout"]("")["Layout"]("layout1")["RadioGroup"]("radiogroup1");
 
  // Obtain the caption of the first item and post it to the test log
  var text = radiogroupObj["wItem"](0);
  Log["Message"](text);
}
Simulating Actions From Keyword Tests
This topic explains how to working with the radio group control in scripts. You can use the described methods and properties in keyword tests too. To do this, use the On-Screen Action or the Call Object Method operations.
See Also
Working With Android Radio Button Controls
Determining a Radio Button's State
