【问题标题】:VBA code not working in UFTVBA 代码在 UFT 中不起作用
【发布时间】:2017-04-24 20:41:53
【问题描述】:

我真的需要你的帮助来解决我自 3 小时以来一直困扰的问题...... 我有一个打开 IE 并导航到 URL 的 VBA 代码。 当我在 Microsoft Visual Basic 中测试代码时,它似乎可以工作:

Sub test()
    On Error Resume Next
        Set app = CreateObject("InternetExplorer.Application")
        MsgBox "OpenWindow 1 : " & Err.Number
        app.Visible = True
        app.Navigate ("salut.com")
        result = Err.Number
        MsgBox "OpenWindow 2 : " & Err.Number
    On Error GoTo 0
    If result <> 0 Then
        Call test
    End If
End Sub

此代码在 Excel 宏中正常工作,但每当我在 UFT(统一功能测试)中执行完全相同的代码时,它都会引发错误:

  • createObject (?) 后出现错误 -2147467261
  • 导航后出现错误 238(我认为这很正常,因为 createObject 失败)

代码完全一样,我只是传递 URL 来导航到函数:

Function openWindow(url)
    On error resume next
        Set app = CreateObject("InternetExplorer.Application")
        app.Visible = true
        app.Navigate(url)
        result =  Err.number
    On error goto 0
    If result <> 0 Then
        openWindow (url)
    End If
End Function

我真的不知道问题是什么......

【问题讨论】:

  • 我想你可能想阅读this。然后将url 声明为ByVal url As String,因此该函数只能采用String。现在我们不确定Navigate 调用是否失败,因为你给了它一些它无法处理的东西——明确的String 参数会使事情变得不那么模棱两可。似乎 UFT 无法处理 CreateObject 调用?
  • 另外,你的函数是递归的,如果出现任何无效的url,或者如果任何事情出错,总会炸毁调用堆栈。
  • UFT 可以很好地处理 CreateObject 调用,但它使用 vbscript,因此您不能显式声明 url As String。我已经在 UFT 中尝试过上面的代码,它对我来说很好......?

标签: vba hp-uft


【解决方案1】:

我找到了解决方法:

Function openWindow(urlToNavigate)
    SystemUtil.Run "iexplore.exe",urlToNavigate
End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 2017-05-16
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多