0
votes

There is an application on which a link is present. Once clicked on the link, it opens up a new browser.

Can someone please help to guide how to select and activate the new window?

I am using UFT for Automation.

1
If both browsers are in the Object Repository, you just need to stop referencing Browser("Browser1") and use Browser("Browser2")? Can you give an example where this isn't working for you? - Dave
Thanks Dave. We have on application which we have automated. Now there is a separate application on which link for 1st application is present. Clicking on that link from the 2nd application invokes 1st application and the control needs to be passed to the 1st application's browser where rest of the function needs to be called. - neeraj
Can you show me the code with which you are having trouble? As I said above you should simply be able to change the browser you refer to and UFT will switch happily between them. - Dave
@Dave he might have issues depending on the Identification properties being used for the browsers. If both were stored using CreationTime:=0 they won't be able to properly switch the reference - Victor Moraes
Additionally i am working on a framework where 1st application has been automated based on the keyword functions. We have a separate test case level function where we open second browser and then click on link which opens 1st application in new browser. There is the challenge. Thanks for the suggestion. i will try to implement both the browser creation and hwnd and let know if it works. - neeraj

1 Answers

0
votes

Using browser collection, we can achieve this. Hope this helps for.

Set objLastBrowser = GetLastBrowserInstance()
Public Function GetLastBrowserInstance()
    Dim objBrowserDesc
    Dim objBrowserCollection
    Dim objLastOpenedBrowser : objLastOpenedBrowser = Null
    Dim intCount
    Dim lngHandle
    Set objBrowserDesc = Description.Create
    objBrowserDesc("micClass").Value = "Browser"
    Set objBrowserCollection = Desktop.ChildObjects(objBrowserDesc)
    intCount = objBrowserCollection.Count
    If intCount > 0 Then
        Set objLastOpenedBrowser = Browser("CreationTime:=" & intCount - 1)
        objLastOpenedBrowser.Sync
        lngHandle = objLastOpenedBrowser.GetROProperty("hwnd")
        Window("hwnd:=" & lngHandle).Activate
    End If
    Set GetLastBrowserInstance = objLastOpenedBrowser
End Function