Search code examples
vbscripthp-uft

In hp-UFT using VB Script can you name an IE browser window in VB Script so that you can control which window does the navigation?


I understand how to open new IE browsers and tabs but is there a way to say:

this is browser1

this is browser2

browser2.navigate(aol.com)

browser1.navigate(stackoverflow.com)


Solution

  • Browsers in UFT can be identified using any unique properties, but these properties can change with the change in the URL you are opening, So there are actually two independent properties which you can use to identify the browsers

    1) Creation time : This is the when the browser is created so, for the first browser its 0, second its 1 and third its 2.

    2) hwnd : its the windows handle for the browser, its the number using which windows OS identifies the objects it creates.

    So now with this understanding, in UFT you can create the browser object for multiple browsers

    1) Simply create the browser objects. 2) To create browser objects

    Set Browser1 = Browser("CreationTime:=0")
    set Browser2 = Browser("CreationTime:=1")
    .
    .
    .
    .
    .
    .
    set Browsern = Browser("CreationTime:=n-1")
    

    You can also use hwnd, but its will not be as easy as creation time.

    now,we can also use the CreateObject for creating the object of IE, but below are the disadvantages to doing so

    1) CreateObject("InternetExplorer.Application") can be used with latest version of IE for the older versions its CreateObject("Internet.Application") for future versions it could be something else.

    2) You will loose the ability to work with in built UFT functions, because when you use createobject then only functions exposed by browser api's will be visible(in UFT's terminology Native functions and properties). What this means is

    You cant write the below code, if you use the createobject function to create the browser object

    Browser1.Sync

    You will have to use an unreliable loop on Readystate property.