title: How to wait for the page to load after click
body: <p>Below is the code for simple IE automation which simply inputs order number like <code>1413105088</code> and postal code which is always <code>78759</code> and clicks on submit button and then from the result page it gets the tracking number like <code>017136295201034</code>
  and puts them in column C.</p>
  
  <p>It works as expected but as IE is not so reliable and slow I was wondering if there is a faster way to do this process and if not can I make it atleast reliable so that it doesn't fails after click on the submit button, meaning the </p>
  
  <pre><code>   Do While IE.Busy Or IE.ReadyState &lt;&gt; 4
          DoEvents
      Loop
  </code></pre>
  
  <p>after </p>
  
  <pre><code>        .document.getElementsByClassName("button_text")(3).Click
  </code></pre>
  
  <p>fails as it doesn't really checks if the ie page has finished loading.</p>
  
  <p>I am asking this as I have to do this for 100s of such request. Thanks in advance.</p>
  
  <blockquote>
    <p>Full code: </p>
  </blockquote>
  
  <pre><code>Sub test()
  
  Dim urL As String, orderNum As String
  Dim trackingNum, prodDetail, cet
  Dim i As Long, fI As Long
  Dim IE
  
  urL = "https://fisher-price.mattel.com/webapp/wcs/stores/servlet/OrderStatusGuestView?catalogId=10101&amp;langId=-1&amp;storeId=10151&amp;krypto=prThs8zyeWG0bkF9ajSr%2FCnzmv1TKodtTEw0EdXtC7NjEmfD3cb6Z75umdkcXCiEPFxvkd0TfHkOswm3ZcMp8sbrU2doZFa6TxVbI%2BW1Lzk%3D"
  
  fI = MAIN.Range("B" &amp; Rows.Count).End(xlUp).Row
  
  Set IE = CreateObject("InternetExplorer.Application")
  
  With IE
      .Visible = True
  
  For i = 2 To fI
  
      orderNum = Trim(MAIN.Range("B" &amp; i).Value)        'Sample ordernum = 1413105088
  
      If orderNum &lt;&gt; "" Then
          .navigate urL
  
          Do While IE.Busy Or IE.ReadyState &lt;&gt; 4
              DoEvents
          Loop
  
          .document.getelementbyid("orderNumber").Value = orderNum
          .document.getelementbyid("postalCode").Value = 78759
          .document.getElementsByClassName("button_text")(3).Click
  
          Application.Wait Now + TimeValue("00:00:02")
          Do While IE.Busy Or IE.ReadyState &lt;&gt; 4
              DoEvents
          Loop
  
          prodDetail = .document.getElementsByClassName("productDetails")(0).innerText
          If InStr(prodDetail, "Tracking :") &gt; 0 Then
              cet = Split(prodDetail, "Tracking :")
              trackingNum = Trim(cet(1))
              MAIN.Range("C" &amp; i).Value = trackingNum
          Else
              MAIN.Range("C" &amp; i).Value = "N/A"
          End If
  
      End If
  
  Next i
  
  End With
  
  IE.Quit
  Set IE = Nothing
  
  
  End Sub
  </code></pre>