Forum Discussion

deepak_chennori's avatar
11 years ago

Dynamic wait for Object To appear on screen

Hi Everyone,



I want to add dynamic wait for an element to appear on screen before click. Does TestComplete provide any function for this.



Thanks & Regards,

Deepak
  • jose_pita's avatar
    jose_pita
    Super Contributor
    See if this works:






    function waitObjectByProperty(property, text, maxTime)


    {

      var object;

      var counter=0;

      if(maxTime== undefined)

        maxTime= 20000;

      if(property== undefined)

        property= "objectIdentifier";

      do

      {

        aqUtils.Delay(100);

        counter+= 100;

        Indicator.PushText(counter);

        if(counter>maxTime)

        {

          Log.Warning("Time Exceeded");

          return;

        }

        object= Sys.Browser(Project.Variables.browser).Page("*").Find(property,text, 30, true);

        Indicator.PopText();

      }

      while (! object.Exists)

      object.Click();

    }

  • chrisb's avatar
    chrisb
    Regular Contributor
    http://support.smartbear.com/viewarticle/56525/



    For testing our web app I use the wait method to wait for the page to load and then search the page for the object I need. You could also put your search for an object inside a loop. Exit the loop when object is found or quit after n number of attempts to find object.
  • You can also use this :



    Function AddDelay(obj_type,obj_name)

      

       Dim Pg, waitFrm, Frame, Frames

                      

       Set Pg =  Aliases.IE.Page("*")

       

    '  Wait for frames

        Pg.wait

        Pg.Refresh

     

     

        waitFrm = True

        Set Frames = GetFrames(Pg) 'Obtain the frames collection

           For Each Frame In Frames

            If Frame.Exists Then

                waitFrm= true 

                 while waitFrm

                        waitFrm = waitFrm And (Frame.readyState <> "complete")

                    If waitFrm Then

                      aqUtils.Delay 100

                    End If

                 WEnd 

    '         Else

    '          Log.Message("No Frame Available")

            End If

          Next

     

        Set Window = Aliases.IE.Page("*")

        cycle = 120

        count = 0

         

        Do While Not (window.NativeWebObject.Find(obj_type,obj_name).Exists)

         Delay(1000)

          count = count +1

          if count = cycle Then 

            Log.Error("Required ' "&obj_name&" ' not found on page.Please look into the issue.")

            Exit Do

          End If

        Loop

       

    End Function

     

                              

     

     

      ' Obtain the frames collection

      Function GetFrames(APage)

        Select Case Options.Web.TreeModel

          Case "DOM" Set GetFrames = APage.document.frames ' DOM model

          Case "Tag" Set GetFrames = APage.FRAME ' Tag model

          Case Else Set GetFrames = APage ' Tree and Hybrid models

        End Select

      End Function