Working With Drop-Down Lists

Applies to TestComplete 15.68, last modified on October 16, 2024

When testing a spinner control, you may need to work with its drop-down list. This topic describes how to do this. The Android Spinner object provides a set of specific properties and methods that you can use to perform certain actions on a drop-down list.

Checking Whether Drop-Down List Is Open

Before selecting an item in a drop-down list, you should open it. Thus, you may need to determine whether the drop-down list is open. Also, you may want your test to perform some actions depending on the state of the drop-down list. You can check the drop-down list's state via the wIsDropDownOpened property that returns True if the drop-down list is open; otherwise, it returns False.

JavaScript, JScript

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

  // Obtain an application
  var app = Mobile.Device().Process("com.example.myapp");

  // Obtain a spinner
  var Spn = app.RootLayout("").Layout("layout").Spinner("spinner");

  // Open the drop-down list if it is closed
  if (!Spn.wIsDropDownOpened)
  {
    Spn.DropDown();
  }
}

Python

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

  # Obtain an application
  app = Mobile.Device().Process("com.example.myapp")

  # Obtain a spinner
  Spn = app.RootLayout("").Layout("layout").Spinner("spinner")

  # Open the drop-down list if it is closed
  if not Spn.wIsDropDownOpened:
    Spn.DropDown()

VBScript

Sub Test
  Dim app, Spn, List

  ' Select an Android device
  Mobile.SetCurrent("MyDevice")

  ' Obtain an application
  Set app = Mobile.Device.Process("com.example.myapp")

  ' Obtain a spinner
  Set Spn = app.RootLayout("").Layout("layout").Spinner("spinner")

  ' Open the drop-down list if it is closed
  If Not Spn.wIsDropDownOpened Then
    Spn.DropDown()
  End If
End Sub

DelphiScript

procedure Test();
var
  app, Spn, List: OleVariant;
begin

  // Select an Android device
  Mobile.SetCurrent('MyDevice');

  // Obtain an application
  app := Mobile.Device.Process('com.example.myapp');

  // Obtain a spinner
  Spn := app.RootLayout('').Layout('layout').Spinner('spinner');

  // Open the drop-down list if it is closed
  if not Spn.wIsDropDownOpened then
    Spn.DropDown();
end;

C++Script, C#Script

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

  // Obtain an application
  var app = Mobile["Device"]["Process"]("com.example.myapp");

  // Obtain a spinner
  var Spn = app["RootLayout"]("")["Layout"]("layout")["Spinner"]("spinner");
  
  // Open the drop-down list if it is closed
  if (!Spn["wIsDropDownOpened"])
  {
    Spn["DropDown"]();
  }
}

Opening and Closing Drop-Down List

To open a drop-down list, you can either use the DropDown action provided by the Android Spinner object, or simulate touch over the control.

You can close the drop-down list via the CloseUp action.

JavaScript, JScript

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

  // Obtain an application
  var app = Mobile.Device().Process("com.example.myapp");

  // Obtain a spinner
  var Spn = app.RootLayout("").Layout("layout").Spinner("spinner");

  // Open the drop-down list if it is closed
  if (!Spn.wIsDropDownOpened)
  {
    Spn.DropDown();
  }
  
  // Close the drop-down list if it is opened
  if (Spn.wIsDropDownOpened)
  {
    Spn.CloseUp();
  }
}

Python

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

  # Obtain an application
  app = Mobile.Device().Process("com.example.myapp")

  # Obtain a spinner
  Spn = app.RootLayout("").Layout("layout").Spinner("spinner")

  # Open the drop-down list if it is closed
  if not Spn.wIsDropDownOpened:
    Spn.DropDown()
      
  # Close the drop-down list if it is opened
  if Spn.wIsDropDownOpened:
    Spn.CloseUp()

VBScript

Sub Test
  Dim app, Spn, List

  ' Select an Android device
  Mobile.SetCurrent("MyDevice")

  ' Obtain an application
  Set app = Mobile.Device.Process("com.example.myapp")

  ' Obtain a spinner
  Set Spn = app.RootLayout("").Layout("layout").Spinner("spinner")

  ' Open the drop-down list if it is closed
  If Not Spn.wIsDropDownOpened Then
    Spn.DropDown()
  End If
  
  ' Close the drop-down list if it is opened
  If Spn.wIsDropDownOpened Then
    Spn.CloseUp()
  End If
End Sub

DelphiScript

procedure Test();
var
  app, Spn, List: OleVariant;
begin

  // Select an Android device
  Mobile.SetCurrent('MyDevice');

  // Obtain an application
  app := Mobile.Device.Process('com.example.myapp');

  // Obtain a spinner
  Spn := app.RootLayout('').Layout('layout').Spinner('spinner');

  // Open the drop-down list if it is closed
  if not Spn.wIsDropDownOpened then
    Spn.DropDown();
  
  // Close the drop-down list if it is opened
  if Spn.wIsDropDownOpened then
    Spn.CloseUp();
end;

C++Script, C#Script

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

  // Obtain an application
  var app = Mobile["Device"]["Process"]("com.example.myapp");

  // Obtain a spinner
  var Spn = app["RootLayout"]("")["Layout"]("layout")["Spinner"]("spinner");
  
  // Open the drop-down list if it is closed
  if (!Spn["wIsDropDownOpened"])
  {
    Spn["DropDown"]();
  }
  
  // Close the drop-down list if it is opened
  if (Spn["wIsDropDownOpened"])
  {
    Spn["CloseUp"]();
  }
}

Obtaining Drop-Down List

When you open a drop-down list, a new Android ListView object, which represents the spinner's drop-down menu, appears in the Object Browser. You can obtain it using the Object Spy window. To learn how to do this, see Addressing Objects in Android Open Applications (Legacy).

The following example demonstrates how to work with a spinner's drop-down list.

JavaScript, JScript

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

  // Obtain an application
  var app = Mobile.Device().Process("com.example.myapp");

  // Obtain a spinner
  var Spn = app.RootLayout("").Layout("layout").Spinner("spinner");

  // Open the drop-down list if it is closed
  if (!Spn.wIsDropDownOpened)
  {
    Spn.DropDown();
  }
  
  // Obtain a ListView object
  List = app.ListView("NO_ID");
  
  // Simulate a scroll of the drop-down menu
  List.smoothScrollByOffset(10);
}

Python

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

  # Obtain an application
  app = Mobile.Device().Process("com.example.myapp")

  # Obtain a spinner
  Spn = app.RootLayout("").Layout("layout").Spinner("spinner")

  # Open the drop-down list if it is closed
  if not Spn.wIsDropDownOpened:
    Spn.DropDown()
  
  # Obtain a ListView object
  List = app.ListView("NO_ID")
  
  # Simulate a scroll of the drop-down menu
  List.smoothScrollByOffset(10)

VBScript

Sub Test
  Dim app, Spn, List

  ' Select an Android device
  Mobile.SetCurrent("MyDevice")

  ' Obtain an application
  Set app = Mobile.Device.Process("com.example.myapp")

  ' Obtain a spinner
  Set Spn = app.RootLayout("").Layout("layout").Spinner("spinner")

  ' Open the drop-down list if it is closed
  If Not Spn.wIsDropDownOpened Then
    Spn.DropDown()
  End If
  
  ' Obtain a ListView object
  Set List = app.ListView("NO_ID")
  
  ' Simulate a scroll of the drop-down menu
  List.smoothScrollByOffset(10)
End Sub

DelphiScript

procedure Test();
var
  app, Spn, List: OleVariant;
begin

  // Select an Android device
  Mobile.SetCurrent('MyDevice');

  // Obtain an application
  app := Mobile.Device.Process('com.example.myapp');

  // Obtain a spinner
  Spn := app.RootLayout('').Layout('layout').Spinner('spinner');

  // Open the drop-down list if it is closed
  if not Spn.wIsDropDownOpened then
    Spn.DropDown();
  
  // Obtain a ListView object
  List := app.ListView('NO_ID');
  
  // Simulate a scroll of the drop-down menu
  List.smoothScrollByOffset(10);
end;

C++Script, C#Script

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

  // Obtain an application
  var app = Mobile["Device"]["Process"]("com.example.myapp");

  // Obtain a spinner
  var Spn = app["RootLayout"]("")["Layout"]("layout")["Spinner"]("spinner");
  
  // Open the drop-down list if it is closed
  if (!Spn["wIsDropDownOpened"])
  {
    Spn["DropDown"]();
  }
  
  // Obtain a ListView object
  List = app["ListView"]("NO_ID");
  
  // Simulate a scroll of the drop-down menu
  List["smoothScrollByOffset"](10);
}

Simulating Actions From Keyword Tests

This topic explains how to work with drop-down list of the spinner control in scripts. You can use the described actions 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 Spinner Controls
Working With Android List View Controls
Android Spinner Support
Android ListView Support

Highlight search results