Xamarin.UITest: How to set date in datepicker on iOS?

Solution 1:

I was able to make it work, but there are few details I had to add. For me the actions that worked for setting time on time picker were:

app.Query(c => c.Class("UIDatePicker").Invoke("setDate", DateTime.Today.AddHours(time.Hour).AddMinutes(time.Minute), "animated", true));
app.Query(c => c.Class("UIDatePicker").Invoke("accessibilityActivate"));

where time was DateTime object with desired time. This worked without adding "animated", true as well.

When trying to check this in REPL I noticed that DateTime.Now does not set picker to the right time, whereas using DateTime.Today works fine. I'm not sure why, maybe someone will investigate this in the future.

I had to invoke accessibilityActivate to save the changes when closing picker. Selected time was not saved in my test app without it. That solved my problem, so I haven't investigated that further