微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

VB.NET UI 自动化 SetValue 操作超时错误

如何解决VB.NET UI 自动化 SetValue 操作超时错误

在基于自动化的项目中,我使用以下代码自动化另一个应用程序。之前它运行良好,但现在它非常频繁地显示“操作超时”错误(10 次尝试中有 9 次)。

我不明白为什么会这样:(

这是代码

Public Shared Sub SetwindowTexBoxText(WindowHandle As Integer,ObjectID As String,ObjectName As String,Value As String)
    Dim baseElement As AutomationElement
    baseElement = AutomationElement.FromHandle(New system.intPtr(WindowHandle))
    Dim oCurPattern As Object
    For Each oElement As AutomationElement In baseElement.FindAll(TreeScope.Descendants,New PropertyCondition(AutomationElement.AutomationIdProperty,ObjectID))
        If oElement.Current.Name = ObjectName Then
            oCurPattern = nothing
            If oElement.TryGetCurrentPattern(Windows.Automation.ValuePattern.Pattern,oCurPattern) = True Then
                CType(oCurPattern,System.Windows.Automation.ValuePattern).SetValue(Value) //error throws on this line
            End If

            Exit For
        End If
    Next
End Sub

最好的问候

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。