Using: ArtOfTest.WebAii.dll 2011.2.1108.0.
Windows 7 x64 / VS2010 / Mstest / Silverlight 4.
Calls to ComboBox.SelectItemByText(...) fail on a databound combobox. In fact, app.Find.ByTextContent(...) also fails. I have attached a minimal test project that has two MsTest tests that demonstrate the issue.
This seems like very basic functionality, so I'm hoping I'm missing something here, otherwise can someone confirm if this is a bug?
Thanks.
Windows 7 x64 / VS2010 / Mstest / Silverlight 4.
Calls to ComboBox.SelectItemByText(...) fail on a databound combobox. In fact, app.Find.ByTextContent(...) also fails. I have attached a minimal test project that has two MsTest tests that demonstrate the issue.
This seems like very basic functionality, so I'm hoping I'm missing something here, otherwise can someone confirm if this is a bug?
Thanks.
5 Answers, 1 is accepted
0
Hello Peter,
I'm sorry for the delay getting back to you.
It looks like you hit a known issue where the TextContent property of the ComboBox returns an empty string instead of an actual text. This is already logged as a bug and should be resolved in near future.
To workaround the issue you can change your code for the first test like this:
Here's the workaround for the second test:
Note that if you want to select an item from the ComboBox you need to open the dropdown first.
Now, to select the item by text you need to create an IEnumerable collection of all items with text "<Select Day>" and take the first one(second marked line in the code above).
I have attached your sample project back with the neccessary corrections.
Hope this helps!
Best wishes,
Plamen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I'm sorry for the delay getting back to you.
It looks like you hit a known issue where the TextContent property of the ComboBox returns an empty string instead of an actual text. This is already logged as a bug and should be resolved in near future.
To workaround the issue you can change your code for the first test like this:
public
void
FindByTextContent_ComboBox()
{
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo(
"http://localhost:16696/SilverlightApplication1TestPage.aspx"
);
SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
ComboBox cb = app.Find.ByType<ComboBox>();
Assert.AreEqual(
"<Select Day>"
, cb.Text);
}
Here's the workaround for the second test:
public
void
SelectByTextContent_ComboBox()
{
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo(
"http://localhost:16696/SilverlightApplication1TestPage.aspx"
);
SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
app.RefreshVisualTrees();
ComboBox combo = app.Find.ByType<ComboBox>();
Assert.IsNotNull(combo);
combo.OpenDropDown(
true
);
combo.Refresh();
var comboItem = combo.Items.Where(item => item.ItemText ==
"<Select Day>"
).FirstOrDefault();
}
Now, to select the item by text you need to create an IEnumerable collection of all items with text "<Select Day>" and take the first one(second marked line in the code above).
I have attached your sample project back with the neccessary corrections.
Hope this helps!
Best wishes,
Plamen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Peter
Top achievements
Rank 1
answered on 17 Nov 2011, 11:33 AM
Thanks for confirming this is a bug, can I track this in PITS (I searched but couldn't find it listed...)?
For the second test, you show how to retrieve the ComboBoxItem that we wish to select, however you don't actually select that item. I couldn't see any method on ComboBox or ComboBoxItem classes to cause that item to be selected in the combobox. How can that be done, since that is the purpose of the test?
For the second test, you show how to retrieve the ComboBoxItem that we wish to select, however you don't actually select that item. I couldn't see any method on ComboBox or ComboBoxItem classes to cause that item to be selected in the combobox. How can that be done, since that is the purpose of the test?
0
Hello Peter,
Here's a link to track the PITS Item: Public URL.
As for the second issue, once the ComboBoxItem is retrieved you just need to click on it to select it. Here's the code:
Best wishes,
Plamen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Here's a link to track the PITS Item: Public URL.
As for the second issue, once the ComboBoxItem is retrieved you just need to click on it to select it. Here's the code:
comboItem.User.Click();
Best wishes,
Plamen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Peter
Top achievements
Rank 1
answered on 17 Nov 2011, 10:22 PM
Thanks, that works, however when I tried to verify the new item had successfully been selected I hit another issue. ComboBox.Text returns the text from ALL TextBlocks, which will be a different value before and after the combobox has been opened. So:
Fails with:
Assert.AreEqual failed. Expected:<Monday>. Actual:<Monday <Select Day> Monday Tuesday>.
Since ComboBox.TextContent is not working, how I can get the selected item text, regardless of whether the combobox has been opened previously or not?
var comboItem = combo.Items.Where(item => item.ItemText == "Monday").FirstOrDefault(); comboItem.User.Click(); Assert.AreEqual("Monday", combo.Text);
Fails with:
Assert.AreEqual failed. Expected:<Monday>. Actual:<Monday <Select Day> Monday Tuesday>.
Since ComboBox.TextContent is not working, how I can get the selected item text, regardless of whether the combobox has been opened previously or not?
0
Hi Peter,
I understand the problem you are facing. It is a common problem with the ComboBox selected item text verification.
To overcome this you need to find the element that contains the selected item text in the Visual Tree. In your case this is a TextBlock(see screenshot).
Here's how to change your code:
Hope this helps!
Regards,
Plamen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I understand the problem you are facing. It is a common problem with the ComboBox selected item text verification.
To overcome this you need to find the element that contains the selected item text in the Visual Tree. In your case this is a TextBlock(see screenshot).
Here's how to change your code:
var comboItem = combo.Items.Where(item => item.ItemText ==
"Monday"
).FirstOrDefault();
comboItem.User.Click();
//Find the TextBlock that contains the selected item text
TextBlock tb = combo.Find.ByType<TextBlock>();
Assert.AreEqual(
"Monday"
, tb.Text);
Hope this helps!
Regards,
Plamen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.