1
我的用戶界面使用自定義控件來表示是/否開關。在UI測試中,我希望能夠在屏幕上控制每次迭代時點擊是或否,但由AutomationID查詢抓取第一個結果。我如何訪問特定自定義控件的子按鈕?我想要點擊的項目是SwitchLPRrec的ButtonNo/ButtonYes和SwitchTowDolly的ButtonNo/ButtonYes。Xamarin.UITest點擊自定義控件的子元素具有相同的自動化ID
自定義開關
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屏幕