Search code examples
hp-uft

How to wait for page load for any browser


During test run, multiple tabs get opened in chrome. As it is opening the new tabs, I would like UFT to wait until complete page loads. I am trying to make it a standard wait without waiting for a specific object.

For example, during run chrome opened, launched URL, click a link, new tab opened, now for the new page to load. Then click a link from 2nd tab and wait for the 3rd page to be loaded.

How can I force UFT to wait for the last page loaded assuming there are multiple tabs?


Solution

  • This will wait till all page is downloaded.

    Browser().Page().Sync
    

    This will wait for particular object

    Browser().Page().Object().Waitproperty
    

    If you want for property of object(s) to change, loop it, like

    Do Until WaitProperty = Argument
        print "Wait. Progress "&Progress
        wait 3 'wait 3 seconds
        Progress = Progress+"." 'add a period to show progress
        Set ObjColl = MyBrowser.ChildObjects(WObj) 
        WaitProperty = cstr(ObjColl(t).GetROProperty(Arg4)) 'get the object property
    Loop
    

    To loop through all pages in a browser:

    'Get Pages count:
    Set browserObject = Description.Create
    browserObject("micclass").Value = "Browser"    
    GetBrowserCount = Desktop.ChildObjects(browserObject).Count
    
    'loop and sync (or any other methods):
    for i = 0 to GetBrowserCount-1
    browser().page("micclass:=Page","CreationTime:="&i,"Title:=.*").Sync
    next