UITestControlNotAvailableException:控件不可用或无效

时间:2010-11-30 10:22:07

标签: .net automated-tests coded-ui-tests

我写了这样的代码:

int timeOut = 300000; //milliseconds
string _displayTextProp = "DisplayText";

WpfText screenResult = MainWindow.UITableStatusControlCustom.ScreenResultLabelValue;

screenResult.WaitForControlExist(timeOut);
screenResult.WaitForControlPropertyNotEqual(_displayTextProp, null, timeOut);
screenResult.WaitForControlPropertyNotEqual(_displayTextProp, "0", timeOut);// (1)

在这个(1)方法中我遇到了异常UITestControlNotAvailableException

测试方法抛出异常: Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotAvailableException:控件不可用或无效。 ---> System.Runtime.InteropServices.COMException:来自HRESULT的异常:0x80042002               在System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode,IntPtr errorInfo)    在System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)    在MS.Internal.Automation.UiaCoreApi.CheckError(Int32 hr)    在MS.Internal.Automation.UiaCoreApi.UiaGetPropertyValue(SafeNodeHandle hnode,Int32 propertyId,Object& value)    在System.Windows.Automation.AutomationElement.GetCurrentPropertyValue(AutomationProperty属性,布尔值ignoreDefaultValue)    在System.Windows.Automation.AutomationElement.GetCurrentPropertyValue(AutomationProperty属性)    在Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaUtility.GetAutomationPropertyValue [T](AutomationElement element,AutomationProperty property)  ---内部异常堆栈跟踪结束---     在Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaUtility.MapAndThrowException(SystemException e,IUITechnologyElement element)    在Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaUtility.GetAutomationPropertyValue [T](AutomationElement element,AutomationProperty property)    在Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaElement.GetAutomationPropertyValue [T](AutomationProperty automationProperty)    在Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaElement.GetRequestedState(AccessibleStates requestedState)    在Microsoft.VisualStudio.TestTools.UITest.Extension.UITechnologyElement.IsState(IUITechnologyElement element,AccessibleStates state)    在Microsoft.VisualStudio.TestTools.UITesting.UITestControl.EnsureValid(Boolean waitForReady,Boolean refetch)    在Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyValue(String propertyName)    在Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetProperty(String propertyName)    在Microsoft.VisualStudio.TestTools.UITesting.UITestControl。<> c_ DisplayClass4。< WaitForControlPropertyNotEqual> b _3(UITestControl ctrl)    在Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForCondition [T](T conditionContext,Predicate 1 conditionEvaluator, Int32 millisecondsTimeout) at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForControlCondition(Predicate 1 conditionEvaluator,Int32 millisecondsTimeout)    在Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForControlPropertyNotEqual(String propertyName,Object propertyValue,Int32 millisecondsTimeout)

这种行为的原因是什么?

感谢您提前!

1 个答案:

答案 0 :(得分:2)

根据this link

当UI测试框架尝试访问不再可用或无法访问的UI元素时,抛出此异常。因此,您可能已经处理了一个项目,或者无法再访问该元素,现在正在尝试访问它。您可能无法初始化其中一个AutomationElements?