Vbscript 当对象不可见时触发链接单击

Vbscript 当对象不可见时触发链接单击,vbscript,qtp,hp-uft,Vbscript,Qtp,Hp Uft,我正在使用UFT 12.51自动化基于IE11的Web应用程序。以下是我的场景: 我必须通过几页来完成我试图自动化的过程(准确地说是9页)。在第4页,我点击一个链接,打开一个框架(作为弹出窗口)。我输入所需信息并单击按钮提交信息,关闭框架并返回浏览器第4页。这里是我的问题开始的地方:在这一点上,UFT停止识别页面上的任何元素。它检测到有一个页面,但不识别它有任何子“可见”对象。如果我再次手动单击链接以再次显示框架,然后它们关闭框架,UFT将再次开始识别页面上的对象。当链接对UFT不可见时,有没有

我正在使用UFT 12.51自动化基于IE11的Web应用程序。以下是我的场景:
我必须通过几页来完成我试图自动化的过程(准确地说是9页)。在第4页,我点击一个链接,打开一个框架(作为弹出窗口)。我输入所需信息并单击按钮提交信息,关闭框架并返回浏览器第4页。这里是我的问题开始的地方:在这一点上,UFT停止识别页面上的任何元素。它检测到有一个页面,但不识别它有任何子“可见”对象。如果我再次手动单击链接以再次显示框架,然后它们关闭框架,UFT将再次开始识别页面上的对象。当链接对UFT不可见时,有没有办法触发链接点击(我有URL)再次打开框架?如果我能做到这一点,我将能够关闭框架,页面上的对象将再次可见。。希望:)

我试过像“DevicePlay”、browser.navigate和sendkeys之类的东西,但都不起作用。不幸的是,由于我的应用程序的性质,我无法提供任何屏幕打印。任何帮助都将不胜感激,因为我一直在努力解决这个问题2天了,现在没有运气

代码

Dim oDR : Set oDR = CreateObject("Mercury.DeviceReplay")
' Lets get the X and Y chordinates for 'Next Step' button
Dim iX, iY

iX = Browser("MyBrowser").Page("MyPage").Link("NextStep").GetROProperty("x") + 5
iY = Browser("MyBrowser").Page("MyPage").Link("NextStep").GetROProperty("y") + 5

If MyFunction(dCurrVals, sErrorMsg) Then
    LOG_ReportEvent "PASS", "Set Investment/Allocate", "Successfully initialised page"
Else
    LOG_ReportEvent "FAIL", "Set Investment/Allocate", sError
End If

'Browser("MyBrowser").Page("MyPage").Object.body.doscroll "scrollbarPageUP"
wait(1)

oDR.MouseMove iX, iY
oDR.MouseClick iX, iY, 0

Set oDR = Nothing

Browser("MyBrowser").RefreshWebSupport
Wait(1)
Browser("MyBrowser").Page("MyPage").Link("Search")
'Browser("MyBrowser").Navigate "MyURL"
'Browser("MyBrowser").Page("MyPage").Sync
'Browser("MyBrowser").Page("MyPage").Link
'Wait(1)
'Browser("MyBrowser").Page("MyPage").Link("Search")
'Browser("MyBrowser").Page("MyPage").WebElement("Search").FireEvent "onclick"
Public Function EnablePage(ByVal oInsightObject, ByVal oCheckObject, ByVal iPgMoveCount ByRef sError)
    LOG_Write vbNewLine & "EnablePage"

    Dim oWS: Set oWS = CreateObject("WScript.shell")
    Dim iC
    Dim bFoundIO

    ' Set default values
    EnablePage = True
    bFoundIO = False

    ' Move to the top of the page
    For iC = 1 To CInt(iPgMoveCount)
        oWS.SendKeys "{PGUP}"
        Wait 0, 500
    Next

    ' Navigate to the bottom of the page to find the object
    For iC = 1 To CInt(iPgMoveCount)
        ' Check if Insight object exists
        If oInsightObject.Exist(1) Then
            bFoundIO = True
            oInsightObject.Click
            Wait 0, 500
            Exit For
        Else
            oWS.SendKeys "{PGDN}"
            Wait 0, 500
        End If
    Next

    ' Check if Insight object was found
    If bFoundIO Then
        ' Check if object to check is visible
        If Not oCheckObject.Exist(2) Then
            EnablePage = False
            sError = "Clicked on Insight Object but unable to find the object to check"
        End If
    Else
        EnablePage = False
        sError = "Unable to find the Insight Object"
    End If

    ' Clear objects
    Set oWS = Nothing

End Function

注意

出于安全原因,我更改了对象的名称,但上面的代码只是我尝试过的一个例子
dCurrVals
是一个字典对象,在函数调用之前已预先填充该对象

这听起来像是UFT中的错误,您应该联系HPE的支持人员


undocumented中提供了此类情况的解决方法,它告诉UFT重新连接到浏览器的DOM。这可能会有所帮助,但由于它没有记录在案,因此无法保证:(

经过大量研究,我找到了解决这个问题的方法。我想不出其他方法来解决这个问题。我想我会把它放在这里,以防其他人面临同样的问题

方法
由于UFT无法识别页面上的任何内容,我决定使用
InsightObject
。使用
InsightObject
的优点是,只要对象可见,UFT就会在页面上找到它。具有讽刺意味的是,这也是一个缺点:对象必须在屏幕上可见。因此我决定编写以下UDF。UDF移动到在页面顶部,然后搜索
InsightObject
。如果未找到该对象,则向下移动页面并再次搜索该对象。它重复此过程,直到找到该对象或达到计数器限制。如果找到
InsightObject
,则单击该对象,然后执行che页上指定对象的ck

UDF

Dim oDR : Set oDR = CreateObject("Mercury.DeviceReplay")
' Lets get the X and Y chordinates for 'Next Step' button
Dim iX, iY

iX = Browser("MyBrowser").Page("MyPage").Link("NextStep").GetROProperty("x") + 5
iY = Browser("MyBrowser").Page("MyPage").Link("NextStep").GetROProperty("y") + 5

If MyFunction(dCurrVals, sErrorMsg) Then
    LOG_ReportEvent "PASS", "Set Investment/Allocate", "Successfully initialised page"
Else
    LOG_ReportEvent "FAIL", "Set Investment/Allocate", sError
End If

'Browser("MyBrowser").Page("MyPage").Object.body.doscroll "scrollbarPageUP"
wait(1)

oDR.MouseMove iX, iY
oDR.MouseClick iX, iY, 0

Set oDR = Nothing

Browser("MyBrowser").RefreshWebSupport
Wait(1)
Browser("MyBrowser").Page("MyPage").Link("Search")
'Browser("MyBrowser").Navigate "MyURL"
'Browser("MyBrowser").Page("MyPage").Sync
'Browser("MyBrowser").Page("MyPage").Link
'Wait(1)
'Browser("MyBrowser").Page("MyPage").Link("Search")
'Browser("MyBrowser").Page("MyPage").WebElement("Search").FireEvent "onclick"
Public Function EnablePage(ByVal oInsightObject, ByVal oCheckObject, ByVal iPgMoveCount ByRef sError)
    LOG_Write vbNewLine & "EnablePage"

    Dim oWS: Set oWS = CreateObject("WScript.shell")
    Dim iC
    Dim bFoundIO

    ' Set default values
    EnablePage = True
    bFoundIO = False

    ' Move to the top of the page
    For iC = 1 To CInt(iPgMoveCount)
        oWS.SendKeys "{PGUP}"
        Wait 0, 500
    Next

    ' Navigate to the bottom of the page to find the object
    For iC = 1 To CInt(iPgMoveCount)
        ' Check if Insight object exists
        If oInsightObject.Exist(1) Then
            bFoundIO = True
            oInsightObject.Click
            Wait 0, 500
            Exit For
        Else
            oWS.SendKeys "{PGDN}"
            Wait 0, 500
        End If
    Next

    ' Check if Insight object was found
    If bFoundIO Then
        ' Check if object to check is visible
        If Not oCheckObject.Exist(2) Then
            EnablePage = False
            sError = "Clicked on Insight Object but unable to find the object to check"
        End If
    Else
        EnablePage = False
        sError = "Unable to find the Insight Object"
    End If

    ' Clear objects
    Set oWS = Nothing

End Function

第4页是否包含所有自定义控件而非web对象?它仅包含web对象(即表、编辑字段、链接等)那么为什么UFT不能识别它呢?你有没有尝试过描述性编程或记录你的步骤?我不知道UFT为什么会停止识别页面上的对象。我尝试过描述性编程和记录,但不幸的是没有成功。使用描述性编程,我得到了相同的结果:我可以识别页面,但无法识别任何对象在页面上。录制:它一直录制到框架关闭,但之后什么都没有。因此,我认为如果我能以某种方式触发链接并再次打开框架,那么我就可以使用它。如果这有任何意义的话——描述性编程、录制和播放、设备重播、对象识别——什么都不起作用。你还有其他选择是使用
GetVisibleText
方法或与开发人员合作。查看此链接以获取其他选项-->这是一个很好的提示@Motti。我尝试了
Browser(“…”)。RefreshWebSupport
,但不幸的是它不起作用(只是显示了一个“常规错误”弹出窗口).根据你的建议,如果我本周没有得到解决方案,我会把它作为UFT中的一个bug提出来