title: Xamarin.UITest Tap Child of Custom Control Where Child Elements Have the Same AutomationID
body: <p>My UI uses a custom control to represent a yes / no switch. On the UI test I would like to be able to tap yes or no for each iteration of the control on the screen but querying by the AutomationID grabs the first result. How can I access the child button of a particular custom control? The items I am looking to tap are SwitchLPRrec's ButtonNo/ButtonYes and SwitchTowDolly's ButtonNo/ButtonYes. </p>
  
  <p><strong>Custom Switch</strong>
  </p>
  
  <pre><code>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) =&gt; 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) =&gt; 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);
          }
  
  }
  </code></pre>
  
  <p><strong>REPL of Screen</strong></p>
  
  <p><a href="https://i.stack.imgur.com/AsTAd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AsTAd.png" alt="enter image description here"></a></p>