Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger a Link Click When an Object is Not Visible

Tags:

I am using UFT 12.51 to automate a Web based application on IE11. Here is my scenario:
I have to go through a few pages to complete the process I'm trying to automate (9 pages to be precise). On page 4, I click on a link which opens a Frame (as a popup). I enter required information and click on the button to submit the information which closes the Frame and returns me to page 4 on the browser. Here is where my problems start: at this point UFT stops recognizing any elements on the page. It picks up that there is a page but does not recognize that it has any child 'visible' objects. If I manually click on the link again to display the Frame again and them close the Frame, UFT starts recognizing the objects on the page again. Is there a way I can trigger a link click (I have the URL) to open the Frame again when the link is not visible to UFT? If I can do that, I will be able to close the Frame and objects on the page will be visible again .. hopefully :)

I have tried things like 'devicereplay', browser.navigate, sendkeys but none of them are working. Unfortunately due to the nature of my app, I cannot provide any screen prints. Any help would be greatly appreciate as I have been trying to figure this out for 2 days now with no luck.

Code

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"


NOTE
For security reason, I have changed the names of object but above code is just an example of things that I have tried. dCurrVals is a dictionary object which is being pre-populated before the function call

like image 580
Zac Avatar asked Jan 11 '17 16:01

Zac


1 Answers

After a lot of research, I have a solution for this problem. I cant think of another way to get round this problem. Thought I'd put it here just incase anyone else is facing the same problem

Approach
As UFT was not recognising anything on the page, I decided to use InsightObject. Advantage of using InsightObject is that as long as the object is visible, UFT will find it on the page. Ironically, this is a disadvantage as well: object has to be visible on the screen. So I decided to write the below UDF. UDF moves to the top of the page, then performs a search for the InsightObject. If the object is not found, it moves the page down and performs another search for the object. It repeats this process until it either finds the object or counter limit is reached. If it finds the InsightObject, it clicks on the object and then performs a check for specified object on the page.

UDF

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
like image 195
Zac Avatar answered Sep 23 '22 10:09

Zac