This is a migrated thread and some comments may be shown as answers.

Automating Selecting an item out of RadComboBox

4 Answers 181 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 28 Jun 2012, 01:46 PM
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);
}

4 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 28 Jun 2012, 02:42 PM
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
0
Joe
Top achievements
Rank 1
answered on 28 Jun 2012, 03:26 PM
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.
0
Accepted
Anthony
Telerik team
answered on 29 Jun 2012, 03:45 PM
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
0
Joe
Top achievements
Rank 1
answered on 29 Jun 2012, 04:47 PM
Thanks Anthony, I've resolved the issue.

This helped me, It was due to the RadComboBox within the popup window.
Tags
General Discussions
Asked by
Joe
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Joe
Top achievements
Rank 1
Share this question
or