How to interact with a DatePicker panel ?

348 views
Skip to first unread message

Alex S

unread,
Dec 20, 2016, 6:44:49 AM12/20/16
to TestStack.White
Hi all,

I could not find any relevant post, so creating a new one.

I need to update a date value in a read-only field which is being updated by a DatePicker type of panel (container?).



I could only get as far as to a <Panel> type of object which has no access to children or other elements:

           
 var list1 = appMainWindow.GetMultiple(SearchCriteria.ByAutomationId("List1"))[0];
 var child1 = ((UIItemContainer)list1).Get<Panel>(SearchCriteria.ByAutomationId("monthCalendar"));


Is the right direction to try this?



Thanks,
Alex

Mike Hetzer

unread,
Dec 30, 2016, 12:12:17 PM12/30/16
to TestStack.White

From TS:White github page.
But this is assuming you have a DateTimePicket UIitem - if this isn't exposed in the inspect tool - i'd say you have a problem then.

DateTimePicker

Currently it supports only Date and not the time. Since there is no native support for DateTimePicker in UIAutomation for setting the value, White uses keyboard to set the value. When the value is set it enters the value, without opening the calendar. Hence it is important for it to know the DateFormat. There are two ways to set the date.

DateTimePicker dateTimePicker = window.Get<DateTimePicker>("dob");
dateTimePicker.Date = DateTime.Now.AddMonth(1);

In this case DateTimePicker would use the configured DateFormat (in case no explicit configuration it uses default format based on the current culture).

DateTimePicker dateTimePicker = window.Get<DateTimePicker>("dob");
dateTimePicker.SetDate(DateTime.Now.AddMonth(1), DateFormat.YearDayMonth);

These are possible DateFormats: DayMonthYear, DayYearMonth, MonthDayYear, MonthYearDay, YearMonthDay and YearDayMonth

Configuring DateFormat

You need to set the DefaultDateFormat property in the configuration file under section Core. The possible values are: "DayMonthYear", "DayYearMonth", "MonthDayYear", "MonthYearDay", "YearMonthDay" and "YearDayMonth"

Alex S

unread,
Jan 3, 2017, 6:58:09 AM1/3/17
to TestStack.White


On Friday, December 30, 2016 at 5:12:17 PM UTC, Mike Hetzer wrote:

From TS:White github page.
But this is assuming you have a DateTimePicket UIitem - if this isn't exposed in the inspect tool - i'd say you have a problem then.



Hi Mike,

This particular DatePicker is not exposed in the inspect tool. It is shown as a pane. 

Trying the following returns me an error "TestStack.White.AutomationException : Failed to get ControlType=pane,AutomationId=monthCalendar"


 
 
DateTimePicker dateTimePicker = appMainWindow.Get<DateTimePicker>(SearchCriteria.ByAutomationId("monthCalendar"));


As a workaround I had to request our Dev team to make the date field editable in "Automation Mode", so I could insert desirable dates straight into field bypassing DatePicker.

Thanks,
Alex
Reply all
Reply to author
Forward
0 new messages