我有这个应用程序,我需要为它编写一些自动化。 查看该应用数据的图片。 我正在使用White / TestStack和C#以及VS2015。
我正在尝试捕获/获取组合框控件(请参阅图像)并使用ComboBox.click()
或Combobox.Select()
方法为其设置值。
看起来我可以获取对象,但是当我在代码ComboBox.click()
或Combobox.Select(1)
中写入时,它会导致“system.invalidoperationexception”异常。
注意 - 如果我在VS2015的“监视”窗口中写入combobox.Click()
,则会执行操作,但如果我写combobox.Select(1)
,则会收到错误。
下面是获取组合框对象的代码。
public static bool ComboBoxByAutomationID(ref TestStack.White.UIItems.WindowItems.Window win, ref
TestStack.White.UIItems.ListBoxItems.ComboBox comboBox, String AutoId)
{
for (int i = 0; i < nofRetries; i++)
{
if (win.Exists<TestStack.White.UIItems.ListBoxItems.ComboBox>(SearchCriteria.ByAutomationId(AutoId)))
{
comboBox = win.Get<TestStack.White.UIItems.ListBoxItems.ComboBox>(SearchCriteria.ByAutomationId(AutoId));
mGenLog.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + ": Found " + AutoId + "[loop: " + i + "]");
return true;
}
mGenLog.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + ": NOT Found " + AutoId + "[loop: " + i + "]");
}
mMainLog.Error(System.Reflection.MethodBase.GetCurrentMethod().Name + ": NOT Found " + AutoId + "[loop: " + nofRetries + "]");
return false;
}
所以,就在“返回true”之前,我补充道:
comboBox.Click();
comboBox.Select(1);
我仍然有例外。
应用数据:
错误:
System.InvalidOperationException未处理HResult = -2146233079 消息=由于对象的当前状态,操作无效。 Source = Interop.UIAutomationClient StackTrace:位于TestStack.White.UIItems的d:\ dev \ UIAComWrapper \ UiaComWrapper \ AutomationElement.cs:第455行的System.Windows.Automation.AutomationElement.SetFocus()中的UIAutomationClient.IUIAutomationElement.SetFocus()。 UIItem.Focus()在C:\ projects \ white-9yaco \ src \ TestStack.White \ UIItems \ UIItem.c中:第301行InnerException: