Forum Discussion

aceishigh's avatar
aceishigh
Contributor
13 years ago

How to use the WaitChild Method to Wait for a web button?

Hi All,

I'm using TestComplete 8.7 on 2008 R2 X64 Server. I'd like to use the WaitChild method to wait for a web button to exist before I try to click it. I've seen the help links about using the WaitChild method but the examples are poor and I'm still confused about how to use it.

Can somebody please post a vbscript example on how to use WaitChild to wait for a simple web button to exist?

Many thanks to you all for your kind help.

John

  • Hi Jack,

    Here is an example of waiting for the web button using the WaitChild method:



    Sub WaitBtn1

      Dim iexplore

      Dim searchform

      TestedApps.Page.Run

      Set iexplore = Sys.Process("IEXPLORE")

      Call iexplore.ToUrl("http://w3schools.com")

      Set searchform = iexplore.Page("http://w3schools.com/").Panel(0).Panel(0).Panel(0).Form("searchform")

        ' Wait for the Search button

      If searchform.WaitChild("SubmitButton(""Search"")", 2000).Exists Then

        ' Child object exists

        searchform.Textbox("as_q").Text = "MyText"

        Call searchform.SubmitButton("Search").Click

      Else

        ' There is no such child

        Log.Warning("The Search button was not found.")

      End If  

    End Sub







    Another way to wait for the needed web element is to call the NativeWebObject.Find method untill the respective element becomes available:



    Sub WaitBtn2

    Dim iexplore

      Dim searchBtn

      TestedApps.Page.Run

      Set iexplore = Sys.Process("IEXPLORE")

      Set Pg = iexplore.ToUrl("http://w3schools.com")

      

      ' Wait for the Search button 

      Do

        aqUtils.Delay 100

        Set searchBtn = Pg.NativeWebObject.Find("title", "Search", "INPUT")

      Loop Until searchBtn.Exists

      Pg.Panel(0).Panel(0).Panel(0).Form("searchform").Textbox("as_q").Text = "MyText"

      searchBtn.Click

    End Sub



    Regards.



    * Run, live to fly, fly to live, Aces high