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
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
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
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
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