WinComboBox: GetProperty of Items not supported on controlType Window

Jul 8, 2013 at 5:53 PM
Edited Jul 8, 2013 at 5:54 PM
I'm attempting to get all choices from a WinCombo box. The control is being identified but .ItemsAsList throws an exception. Thanks !

Here is my code:
    [CodedUITest]
    public class myTestSuite
    {
        [TestMethod]
        public void MyTestMethod()
        {
            myActions actions = new myActions();
            Assert.IsTrue(actions.GetCboItems() == 1);
        }
    }

    class myActions
    {
        public int GetCboItems()
        {
            MyUIMap map = new MyUIMap();
            CUITe_WinComboBox cbo = map.cboNavigation();
            List<string> items = cbo.ItemsAsList;

            return items.Count;
        }
    }

    class MyUIMap : CUITe_WinWindow
    {
        public MyUIMap() : base("Name= <snipped for privacy> ") { }

        public CUITe_WinComboBox cboNavigation() { return Get<CUITe_WinComboBox>("ClassName=  <snipped for privacy> "); }
    }
The exception:
System.NotSupportedException was unhandled by user code
  HResult=-2146233067
  Message=GetProperty of "Items" is not supported on control type: Window
  Source=Microsoft.VisualStudio.TestTools.UITesting
  StackTrace:
       at Microsoft.VisualStudio.TestTools.UITesting.PropertyProviderBase.ThrowNotSupportedException(Boolean isNotSupported)
       at Microsoft.VisualStudio.TestTools.UITesting.WinPropertyProvider.GetPropertyValueInternal(UITestControl uiControl, String propertyName)
       at Microsoft.VisualStudio.TestTools.UITesting.PropertyProviderBase.GetPropertyValue(UITestControl uiControl, String propertyName)
       at Microsoft.VisualStudio.TestTools.UITesting.WinPropertyProvider.GetPropertyValue(UITestControl uiControl, String propertyName)
       at Microsoft.VisualStudio.TestTools.UITesting.UITestPropertyProvider.GetPropertyValueWrapper(UITestControl uiControl, String propertyName)
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyValuePrivate(String propertyName)
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyPrivate(String propertyName)
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.<>c__DisplayClass11.<GetProperty>b__10()
       at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetProperty(String propertyName)
       at Microsoft.VisualStudio.TestTools.UITesting.WinControls.WinComboBox.get_Items()
       at CUITe.Controls.WinControls.CUITe_WinComboBox.get_ItemsAsList() in c:\Working\codeplex\cuite\CUITe\Controls\WinControls\CUITe_WinComboBox.cs:line 40
       at myNamespace.myActions.GetCboItems() in \Class1.cs:line 30
       at myNamespace.myTestSuite.MyTestMethod() in \Class1.cs:line 19
  InnerException: NULL
Coordinator
Jul 16, 2013 at 6:40 AM
Hi dentaylor,

I have not tried to use the ClassName search property in win controls.

Maybe you can try using the Name search property as follows:
public CUITe_WinComboBox cboNavigation() { return Get<CUITe_WinComboBox>("Name=  <snipped for privacy> "); }
If that does not work, can you send me a sample win32 exe that contains the combo box control so I can try to reproduce it on my end please?

Thank you.