0

在以下时间选择器的 Xamarin 表单中

在此处输入图像描述

如何更改 xamarin UI 测试的时间选择器值。我可以打开时间选择器,但不知道如何更改时间。这是时间选择器的 app.Repl() 树的屏幕截图。

在此处输入图像描述

这是我试图改变时间的尝试。

app.WaitForElement(c => c.Marked("hours"));
app.Tap(c => c.Marked("hours"));
app.EnterText(c => c.Marked("hours"), newHours) // errors can't pull up keyboard
4

1 回答 1

1

我发现处理日期和时间控件的最简单方法是使用 Invoke 方法来访问在时间/日期选择器控件中公开的后门。

// invokes a method to input the hour into the picker, time format is 24 hour
app.Query(c => c.Class("RadialTimePickerView").Invoke("setCurrentHour", (int)hour));

// invokes a method to input the minute into the picker
app.Query(c => c.Class("RadialTimePickerView").Invoke("setCurrentMinute", (int)minute));

日期选择器非常相似,但它不需要两个单独的方法,它只使用一个。

// invokes a method to input the date into the picker, where month starts from 0
app.Query(c => c.Raw("DatePicker").Invoke("updateDate", (int)year, (int)month - 1, (int)day));

我建议使用这个特殊的后门,因为它适用于各种 android 版本,因为每个版本的 android 都有略微不同的日期/时间选择器样式。

于 2017-12-20T22:58:28.737 回答