我的 UI 使用自定义控件来表示是/否开关。在 UI 测试中,我希望能够为屏幕上控件的每次迭代点击是或否,但通过 AutomationID 查询会获取第一个结果。如何访问特定自定义控件的子按钮?我要点击的项目是 SwitchLPRrec 的 ButtonNo/ButtonYes 和 SwitchTowDolly 的 ButtonNo/ButtonYes。
自定义开关
public RC_Switch_YesNo()
{
try
{
this.HorizontalOptions = LayoutOptions.Center;
this.VerticalOptions = LayoutOptions.Center;
negative = new Button();
negative.Text = "No";
negative.AutomationId = "ButtonNo";
negative.Style = AppStyling.Style_Button_Switch;
negative.Clicked += (o, s) => OnSelectedItemChanged(this, ItemSelected, (int)Enums_RecoveryConnect.SelectionStatus.SelectionFalse);
positive = new Button();
positive.Text = "Yes";
positive.AutomationId = "ButtonYes";
positive.Style = AppStyling.Style_Button_Switch;
positive.Clicked += (o, s) => OnSelectedItemChanged(this, ItemSelected, (int)Enums_RecoveryConnect.SelectionStatus.SelectionTrue);
if(Device.Idiom == TargetIdiom.Tablet)
{
negative.HeightRequest = (int)AppStyling.TabletEntry.TabletHeight;
positive.HeightRequest = (int)AppStyling.TabletEntry.TabletHeight;
negative.FontSize = (int)AppStyling.TabletEntry.TabletEntryTextSize;
positive.FontSize = (int)AppStyling.TabletEntry.TabletEntryTextSize;
}
this.Children.Add(negative, 0,0);
this.Children.Add(positive, 1,0);
}
catch(System.Exception ex)
{
Helpers.Helper_ErrorHandling.SendErrorToServer(ex);
}
}
屏幕的 REPL