C# SelectedIndex为没有大量列表项的WpfCombobox引发错误

C# SelectedIndex为没有大量列表项的WpfCombobox引发错误,c#,coded-ui-tests,C#,Coded Ui Tests,我们正在使用C#测试一个带有CodedUi的WPF应用程序。在我们的应用程序中,我们有一个包含大量列表项(16个列表项)的组合框。组合框有一个用于列表项的滚动条。使用SelectedIndex从wpfcombobox中选择列表项时,出现以下错误: 结果堆栈跟踪: 在Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IsScreenElement.SetValueAsComboBox(字符串bstrNewValue,Int32 NSET

我们正在使用C#测试一个带有CodedUi的WPF应用程序。在我们的应用程序中,我们有一个包含大量列表项(16个列表项)的组合框。组合框有一个用于列表项的滚动条。使用
SelectedIndex
从wpfcombobox中选择列表项时,出现以下错误:

结果堆栈跟踪:
在Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IsScreenElement.SetValueAsComboBox(字符串bstrNewValue,Int32 NSETValueAsComboxFlag)
在Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.SetValueAsComboxInternal(字符串值,SetValueAsComboxType SetValueAsComboxType)
位于Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.SetValueAsComboxUsingQueryId(字符串值) 在Microsoft.VisualStudio.TestTools.UITesting.TechnologyElementPropertyProvider.SetValueUsingQueryId(UITestControl uiControl,Int32[]选择的骰子,字符串technologyName,Int32 maxCount) 位于Microsoft.VisualStudio.TestTools.UITesting.WPFComboxPropertyProvider.SetPropertyValue(UITestControl UITestControl,字符串propertyName,对象值) 位于Microsoft.VisualStudio.TestTools.UITesting.UiaPropertyProvider.SetPropertyValue(UITestControl UITestControl,字符串propertyName,对象值) 位于Microsoft.VisualStudio.TestTools.UITesting.UITestPropertyProvider.SetPropertyValueWrapper(UITestControl uiControl,字符串propertyName,对象值) 位于Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetPropertyValue(字符串propertyName,对象propertyValue) ---内部异常堆栈跟踪的结束--- 位于Microsoft.VisualStudio.TestTools.UITesting.Playback.MapandRowComeException(ComeException innerException,IPlaybackContext上下文) 位于Microsoft.VisualStudio.TestTools.UITesting.Playback.MapandRowException(异常异常,IPlaybackContext上下文) 在Microsoft.VisualStudio.TestTools.UITesting.Playback.MapandRowException(异常异常、字符串操作名、UITestControl uiControl) 在Microsoft.VisualStudio.TestTools.UITesting.Playback.MapandRowException(异常异常、字符串操作名、对象参数值、UITestControl uiControl) 位于Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetPropertyValue(字符串propertyName,对象propertyValue) 位于Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetPropertyPrivate(字符串propertyName,对象值) 在Microsoft.VisualStudio.TestTools.UITesting.UITestControl.c__DisplayClass180_0.b__0()中 在Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1函数、UITestControl控件、布尔firePlaybackErrorEvent、布尔LogaAction) 位于Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetProperty(字符串propertyName,对象值) 在Microsoft.VisualStudio.TestTools.UITesting.WpfControls.WpfComboBox.set\u SelectedIndex(Int32值)中 在D:\VSTS2015\MC2Main\MC2.Tests.CUIT.Handwrited.UnitConversion.Unit\U Conversion.UnitConverterLargeUnits()中的MC2.Tests.CUIT.Handwrited.UnitConversion.UnitConversion.Unit\UnitConversion.cs:第333行 结果消息: 试验方法MC2.Tests.CUIT.Handwrite.UnitConversion.Unit\U Conversion.UnitConverter大型单元引发异常: Microsoft.VisualStudio.TestTools.UITest.Extension.PlaybackFailureException:无法在控件上执行值为“0”的SelectedIndex的“SetProperty”。其他详情: 技术名称:“UIA” 框架:“WPF” ControlType:“组合框” AutomationId:'UnitConvertServiceModel\u ToUnit\u组合框' --->System.Runtime.InteropServices.ComeException:来自HRESULT的异常:0xF004F006

列表项选择的代码如下所示:

DataTable dt = commonfunc.getExcelDataUsingConnection(excelConn, sheetname);

foreach (DataRow row in dt.Rows)
{
   fromunit = row["FromUnit"].ToString();
   tounit = row["ToUnit"].ToString();
   tounitexpvalue = row["ExpectedValue"].ToString();
   fromunitname = row["InputUnit"].ToString();
   tounitname = row["OutputUnit"].ToString();

   WpfComboBox funit = new WpfComboBox();

   funit = commonfunc.GetCUITCombobox(parent, "automationID",     "UnitConverterViewModel_FromUnit_comboBox", 0);

   Mouse.Click(funit);
}

for (int test = 0; test < funit.Items.Count; test++)
{

     string txt = funit.Items[test].GetChildren()[0].FriendlyName;

        if (txt.ToLower().Trim() == fromunitname.ToLower().Trim())
           {
                funit.SelectedIndex = test;
                break;
           }

}

WpfListItem fromUnitItem = new WpfListItem();
fromUnitItem = commonfunc.GetCUITListItem(funit, "automationId", fromunit, 0);
funit.Expanded = true;
Mouse.Click(fromUnitItem);
DataTable dt=commonfunc.getExcelDataUsingConnection(excelConn,sheetname);
foreach(数据行中的数据行)
{
fromunit=行[“fromunit”]。ToString();
tounit=行[“tounit”]。ToString();
tounitexpvalue=行[“ExpectedValue”]。ToString();
fromunitname=行[“InputUnit”]。ToString();
tounitname=行[“OutputUnit”].ToString();
WpfComboBox funit=新WpfComboBox();
funit=commonfunc.getcuitcompobox(父级,“automationID”,“UnitConverterViewModel\u FromUnit\u组合框”,0);
鼠标。点击(funit);
}
对于(int test=0;test