Automating Selecting an item out of RadComboBox

5 posts, 1 answers
  1. Joe
    Joe avatar
    2 posts
    Member since:
    Jun 2012

    Posted 28 Jun 2012 Link to this post

    Hello,

    I'm using the Telerik Testing Framework to do UI Automation within a Silverlight application.
    I was wondering how I can automate a user selecting an item from a RadControlBox in a programmatic manner.

    Thanks, Joe
    [TestMethod]
    public void UIChecks ()
    {
        _RadComboBox CB_Boundary = myApp.FindName<RadComboBox>("CB_Boundary");
        Assert.IsNotNull(CB_Boundary);
          
        Sleep(1);
        // Don't know how to click on RadComboBoxItems, this maybe?
        CB_Boundary.User.Click();
         
        //ArgumentException
        //ComboBox contains no items to search in and select! Please make sure the test case opens
        CB_Boundary.SelectItem("Boundry", true);
        //Select Boundry Item
        Sleep(1);
    }
  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 28 Jun 2012 Link to this post

    Hello Joe,

    The following code works against a Telerik Silverlight RadComboBox demo site:

    Settings.Current.Web.EnableSilverlight = true;
    Manager.LaunchNewBrowser();
    ActiveBrowser.NavigateTo("http://demos.telerik.com/silverlight/#ComboBox/FirstLook");
    SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
     
    Telerik.WebAii.Controls.Xaml.RadComboBox cb = app.Find.ByAutomationId<Telerik.WebAii.Controls.Xaml.RadComboBox>("TechnologySelection");
    Assert.IsNotNull(cb);
    cb.SelectItem("Silverlight", true);
     
    System.Threading.Thread.Sleep(1000);

    You should not need to click it first to open it. The second argument of SelectItem dictates whether to open the drop-down before making the selection.

    All the best,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Joe
    Joe avatar
    2 posts
    Member since:
    Jun 2012

    Posted 28 Jun 2012 Link to this post

    Thanks Anthony, but I'm still receiving an error.
    Attached is where I encounter the error.

    This is what I changed my above to after trying the example you gave me and implementing it as my own:
    _RadComboBox CB_Boundary = myApp.Find.ByAutomationId<RadComboBox>("CB_Boundary");
    Assert.IsNotNull(CB_Boundary);

    Sleep(1);
    CB_Boundary.SelectItem("Boundry", true);

    The code behind for the xaml is the following :

    void client_GetAllBoundariesCompleted(object sender, MSPWeb.GetAllBoundariesCompletedEventArgs e)
    {
        List<string> temp = e.Result.ToList();
     
        foreach (string item in temp)
        {
            CB_Boundary.Items.Add(item);
        }
        assignvalue(CB_Boundary, _meter.MeterType);
        CheckCallBack();
    }

    I can assume that the items are not loaded when selectItem is called.
    The service is called to add to the combobox items, but for some reason, it doesn't see any of it.
  4. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 29 Jun 2012 Link to this post

    Hello Joe,

    Let's try explicitly opening and refreshing the ComboBox before making a selection:

    cb.ToggleDropDown();
    cb.Refresh();
    cb.SelectItem("Silverlight", false);

    If that still doesn't work, please point us to a public site that demonstrates the issue so we can have a local reproduction. If your app is private or that info is too sensitive for a public forum, consider asking your developers to craft a small sample app that contains a single RadComboBox that demonstrates the issue.

    All the best,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  5. Joe
    Joe avatar
    2 posts
    Member since:
    Jun 2012

    Posted 29 Jun 2012 Link to this post

    Thanks Anthony, I've resolved the issue.

    This helped me, It was due to the RadComboBox within the popup window.
Back to Top