VBA 代码在 UFT 中不起作用
VBA code not working in UFT
我真的需要你的帮助来解决一个我被困了 3 个小时的问题...
我有一个 VBA 代码可以打开 IE 并导航到 URL。
当我在 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(我认为这很正常,因为
创建对象失败)
代码完全一样,我只是通过 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
我真的不知道问题是什么...
我找到了解决方法:
Function openWindow(urlToNavigate)
SystemUtil.Run "iexplore.exe",urlToNavigate
End Function
我真的需要你的帮助来解决一个我被困了 3 个小时的问题... 我有一个 VBA 代码可以打开 IE 并导航到 URL。 当我在 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(我认为这很正常,因为 创建对象失败)
代码完全一样,我只是通过 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
我真的不知道问题是什么...
我找到了解决方法:
Function openWindow(urlToNavigate)
SystemUtil.Run "iexplore.exe",urlToNavigate
End Function