Specific Features of DatePicker Control

Applies to TestComplete 15.47, last modified on January 20, 2023
Checking if Calendar and Spinners are Shown

For the most part, the methods and properties of the date picker controls are the same as for the calendar controls, however there are several specific to DatePicker.

DatePicker controls my display number pickers, calendar or both. To check whether the calendar is shown, use the DEFAULT_CALENDAR_VIEW_SHOWN field. If the calendar is shown, this field contains True; otherwise - False. You can also check whether the number pickers are shown by using the similar DEFAULT_SPINNERS_SHOWN field. The following example checks whether the calendar is shown and posts result to the log:

JavaScript, JScript

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

  // Obtain the CalendarView object
  var p = Mobile.Device().Process("com.example.myapp");
  var DatePicker = p.RootLayout("", 2).Layout("content").DatePicker("datePicker");
  
  // Get the min and max dates
  var CalendarShown = DatePicker.DEFAULT_CALENDAR_VIEW_SHOWN;
  
  // Post dates to the log
  Log.Message(CalendarShown);
}

Python

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

  # Obtain the CalendarView object
  p = Mobile.Device().Process("com.example.myapp")
  DatePicker = p.RootLayout("", 2).Layout("content").DatePicker("datePicker")
  
  # Get the min and max dates
  CalendarShown = DatePicker.DEFAULT_CALENDAR_VIEW_SHOWN
  
  # Post dates to the log
  Log.Message(CalendarShown)

VBScript

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

  ' Obtain the CalendarView object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set DatePicker = p.RootLayout("", 2).Layout("content").DatePicker("datePicker")
  
  ' Get the min and max dates
  CalendarShown = DatePicker.DEFAULT_CALENDAR_VIEW_SHOWN
  
  ' Post dates to the log
  Log.Message(CalendarShown)
End Sub

DelphiScript

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

  // Obtain the CalendarView object
  p := Mobile.Device.Process('com.example.myapp');
  DatePicker := p.RootLayout('', 2).Layout('content').DatePicker('datePicker');
  
  // Get the min and max dates
  CalendarShown := DatePicker.DEFAULT_CALENDAR_VIEW_SHOWN;
  
  // Post dates to the log
  Log.Message(CalendarShown);
end;

C++Script, C#Script

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

  // Obtain the CalendarView object
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var DatePicker = p["RootLayout"]("", 2)["Layout"]("content")["DatePicker"]("datePicker");
  
  // Check whether the calendar is shown
  var CalendarShown = DatePicker["DEFAULT_CALENDAR_VIEW_SHOWN"];
  
  // Post result to the log
  Log["Message"](CalendarShown);
}

Note: Though you can also use methods and properties of Number Picker and Calendar View controls to select a date, we recommend using methods and properties of the DatePicker object, as this hides the details of control implementation from tests.
Simulating Actions From Keyword Tests

This topic explains how to work with the date picker 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 Calendar Controls
Android CalendarView Support
Determining and Changing Calendar Date

Highlight search results