I'm trying to set UIPickerView value using UITest and it does not looks like AppQuery can figure out the element to select.
Is there a solution for this?
I have been using this code, courtesy StackOverflow, but it does not seem to solve the problem.
Any help is appreciated.
public static bool SetPicker (this IApp app, int index, string name)
{
if (string.IsNullOrEmpty (name)) {
throw new ArgumentNullException (nameof (name));
}
if (Device.OS == TargetPlatform.Android) { var results = app.Query (c => c.Class ("numberPicker").Invoke ("setValue", index)); app.Tap (c => c.Marked ("OK")); return results.Any (); } /// Assuming a single column picker // Try to scroll and find the text item only 5 times for (int i = 0; i < 5; i++) { if (app.Query (m => m.Marked (name)).Length == 0) { app.ScrollUp (x => x.Class ("UIPickerTableView"), ScrollStrategy.Programmatically); Debug.WriteLine (i); } else { app.ScrollDown (name); app.Tap (x => x.Marked (name)); break; } } return true; }
Posts
This seems to be a deficiency in the Xamarin UI test (common problem, no built-in solution). Here's the best I've found:
https://forums.xamarin.com/discussion/30339/controlling-a-picker-android-numberpicker-ios-uipickerview-from-uitest
Here is an extension method I came up with for setting a simple iOS UIPickerView:
I use library named "FormsTest" with Xamarin.UITest (https://github.com/pranart/FormsTest)
This library will let you get almost every property value from Xamarin.Forms Controls.