【问题标题】:UITestControlNotAvailableException: The control is not available or not validUITestControlNotAvailableException:控件不可用或无效
【发布时间】:2010-11-30 10:22:07
【问题描述】:

我写过这样的代码:

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 错误代码,IntPtr 错误信息) 在 System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 错误代码) 在 MS.Internal.Automation.UiaCoreApi.CheckError(Int32 小时) 在 MS.Internal.Automation.UiaCoreApi.UiaGetPropertyValue(SafeNodeHandle hnode,Int32 propertyId,Object& 值) 在 System.Windows.Automation.AutomationElement.GetCurrentPropertyValue(AutomationProperty 属性,布尔忽略默认值) 在 System.Windows.Automation.AutomationElement.GetCurrentPropertyValue(AutomationProperty 属性) 在 Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaUtility.GetAutomationPropertyValue[T](AutomationElement 元素,AutomationProperty 属性) --- 内部异常堆栈跟踪结束 --- 在 Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaUtility.MapAndThrowException(SystemException e,IUITechnologyElement 元素) 在 Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaUtility.GetAutomationPropertyValue[T](AutomationElement 元素,AutomationProperty 属性) 在 Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaElement.GetAutomationPropertyValue[T](AutomationPropertyautomationProperty) 在 Microsoft.VisualStudio.TestTools.UITest.Extension.Uia.UiaElement.GetRequestedState(AccessibleStates requestedState) 在 Microsoft.VisualStudio.TestTools.UITest.Extension.UITechnologyElement.IsState(IUITechnologyElement 元素,AccessibleStates 状态) 在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.EnsureValid(布尔 waitForReady,布尔重新获取) 在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyValue(String propertyName) 在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetProperty(String propertyName) 在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.c_DisplayClass4.b_3(UITestControl ctrl) 在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForCondition[T](T conditionContext, Predicate1 conditionEvaluator, Int32 millisecondsTimeout) at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForControlCondition(Predicate1 conditionEvaluator, Int32 毫秒超时) 在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForControlPropertyNotEqual(String propertyName, Object propertyValue, Int32 millisecondsTimeout)

什么原因会导致这种行为?

感谢您的提前!

【问题讨论】:

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


    【解决方案1】:

    根据this link

    当 UI 测试框架尝试访问不再可用或无法访问的 UI 元素时,将引发此异常。因此,您可能已经处置了一个项目,或者不再有权访问该元素并且现在正在尝试访问它。您可能未能初始化其中一个 AutomationElement?

    【讨论】:

    • 谢谢马克。 “所以您可能已经处置了一个项目,或者不再有权访问该元素并且现在正在尝试访问它”我可以使用什么方法来解决这个问题?
    • 您需要查看已创建的对象 - 确保在尝试访问它们时已创建它们。如果有帮助,请先检查对象是否已初始化并且是否为 != null。
    • 感谢马克。就我而言,我添加了 screenResult.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
    • 所以在这种情况下我的控件没有被缓存并且播放总是找到它。这对我有帮助。
    • @Mark Mayo,就我而言,我无法运行相同的记录测试(涉及 WPF 等)两次。我得到完全相同的错误。我试图了解发生了什么,但您提供的链接并不完全冗长。那么,我能做些什么呢?如何更改已记录测试的搜索配置?谢谢。
    猜你喜欢
    • 1970-01-01
    • 2022-09-27
    • 2021-05-24
    • 2018-07-28
    • 2011-08-04
    • 2017-07-07
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多