Verify Silverlight ComboBox Contains Specific Text

PROBLEM

I would like to iterate through a Silverlight ComboBox and verify that it contains specific text strings.

SOLUTION

This is possible with a coded solution. The example below is against this Silverlight demo site.

 

After navigating there, click DataForm in the left-hand menu. Then open the CommandButtonsVisibility ComboBox. Finally, add a coded step:

 

Note: Text only gives that element's text. As of version 2011.2.1229, use TextBlockContent on the parent element to recursively search for the text within its children.
      Click here to show code for an earlier version using Text.

 

C#

ComboBox cb = Pages.SilverlightToolkitSamples.SilverlightApp.Item0Combobox;
bool found = cb.TextBlockContent.Contains(Data["Col1"].ToString());
 
Log.WriteLine("Match found: " + found.ToString());
Assert.IsTrue(found);

 

Visual Basic

Dim cb As ComboBox = Pages.SilverlightToolkitSamples.SilverlightApp.Item0Combobox
Dim found As Boolean = cb.TextBlockContent.Contains(Data("Col1").ToString())
 
Log.WriteLine("Match found: " + found.ToString())
Assert.IsTrue(found)