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

RadComboBox. Select value

5 Answers 18 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Olga
Top achievements
Rank 1
Olga asked on 09 Feb 2017, 03:40 PM

Hi, 

i use telerik framework and visual studio 2015 to create automation tests for Silverlight application.

On UI page i have RadComboBox. If i click on it i'll get dropdownlist. I need to select value from that dropdownlist.  

Here is my code. But it does not work. 

var edits_rcb = FMapp.Find.AllByType<RadComboBox>();
edits_rcb[1].User.Click();
edits_rcb[1].SelectItem("EU", true);

 

I also can't get elements by this way: var elements = edits_rcb[1].ItemElements; I got empty  elements. 

i have following code for RadComboBox in xaml file 

dataform:DataField Label="Region" Foreground="{StaticResource vvosTextBrush}">
                <telerik:RadComboBox ItemsSource="{Binding RegionList}"
 SelectedValue ="{Binding Region, Mode=TwoWay}"
DisplayMemberPath="RegionCode"
 Style="{StaticResource RadComboBoxStyle}"/>
</dataform:DataField>

5 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 14 Feb 2017, 11:50 AM
Hello Olga,

From what I can see from the provided code you click in the ComboBox (which would open the dropdown) and then you call the SelectItem method with second parameter true, which would click again in the ComboBox and it would close it. The closing would occur before the item is selected and you would observe open and close of the dropdown without selecting an item. Please note that this is just a guess and in order to fix it you can try removing the first click.

Nevertheless as this might not be the exact issue you are facing I am attaching a sample project with a test showing how you can select item from ComboBox inside DataForm.

Also, please note that before the dropdown of the ComboBox is opened its items are not loaded in the visual tree and  the ItemElements collection would be empty. So in order to work correctly you would need to open the dropdown, call the Refresh method of the ComboBox (in order to refresh it and particularly to populate the ItemElements collection, this is recommended in scenarios when there are elements shown\hidden) and then select item from the ItemElements collection. This approach can be also found in the attached project.

Hope this would help.

Regards,
Georgi
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Olga
Top achievements
Rank 1
answered on 16 Feb 2017, 04:40 PM

Hi, 

i try following:

var dataFrom = FMapp.Find.ByType("DataForm");
var radcbb = dataFrom.Find.AllByType<RadComboBox>();
radcbb[1].SelectItem("EU", true);

I got following error: 

ComboBox contains no items to search in and select! Please make sure the test case opens the drop down first

But during test running i see that 

 

0
Olga
Top achievements
Rank 1
answered on 16 Feb 2017, 04:42 PM
But during test running i see that drop down list was opened 
0
Olga
Top achievements
Rank 1
answered on 16 Feb 2017, 04:46 PM

i also try this

var dataFrom = FMapp.Find.ByType("DataForm");
var radcbb = dataFrom.Find.AllByType<RadComboBox>();
radcbb[1].User.Click();
radcbb[1].Refresh();
var elems = radcbb[1].ItemElements;

and elems is empty

 

0
Georgi
Telerik team
answered on 20 Feb 2017, 02:31 PM
Hi Olga,

Did you try setting a wait before looking for the elements after the dropdown is opened:
var dataFrom = FMapp.Find.ByType("DataForm");
var radcbb = dataFrom.Find.AllByType<RadComboBox>();
radcbb[1].User.Click();
Thread.Sleep(1000);
radcbb[1].WaitDropDownAnimation();
radcbb[1].Refresh();
var elems = radcbb[1].ItemElements;

Usually the WaitDropDownAnimation method should do the job.

Also did you have the chance to check if this works with the SelectItem method (as shown in the previously  attached project)?
‚Äč

Nevertheless I see that you have a custom style for the RadComboBox and if you are changing the template of the control, please note that in order for the ItemElemts collection to be populated the scrollviewer(PART_ScrollViewer) in witch they are located should be present.

Other approach that you can use is to find the items yourself:
var dataFrom = FMapp.Find.ByType("DataForm");
var radcbb = dataFrom.Find.AllByType<RadComboBox>().FirstOrDefault();
radcbb .ToggleDropDown();
radcbb .WaitDropDownAnimation();
radcbb .Refresh();
var item = radcbb .DropDownPopup.Find.AllByType<RadComboBoxItem>().Where(i => i.Text.Equals("Security")).FirstOrDefault();
item.User.Click();

Hope this will shine some light on the matter.

Regards,
Georgi
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ComboBox
Asked by
Olga
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Olga
Top achievements
Rank 1
Share this question
or