title: Alternate way for sleep function
body: <p>I have VBScript which is use to pass the test case in HP QC.</p>
  
  <p>How it works:
  By passing shortkeys of each button under each step.</p>
  
  <p>Challenge:
  Currently I am using <code>Sleep</code> in between two shortkeys.
  But sometimes if the next window is not loaded and my sleep time is over 
  the script will fail.</p>
  
  <p>How to solve this issue?</p>
  
  <pre><code>Set objShell = CreateObject("WScript.Shell")
  WScript.Sleep 5000
  n = InputBox("Enter No of TC's","???")
  WScript.Sleep 2000
  objShell.SendKeys "^ "
  WScript.Sleep 4000
  For m = 1 To n-1
      objShell.SendKeys "+{DOWN}"
  Next
  WScript.Sleep 5000
  objShell.SendKeys "^%{F9}"
  WScript.Sleep 5000 
  For x = 1 To n
      WScript.Sleep 8000
      objShell.SendKeys "^r"
      WScript.Sleep 8000
      objShell.SendKeys "{ENTER}"
      WScript.Sleep 3000
      objShell.SendKeys "+{TAB}"
      WScript.Sleep 1000
      objShell.SendKeys "+{TAB}"
      WScript.Sleep 1000
      objShell.SendKeys "+{TAB}"
      WScript.Sleep 1000
      objShell.SendKeys "{ENTER}"
      WScript.Sleep 2000
      For y = 1 To 1
          objShell.SendKeys "As Expected : "
          objShell.SendKeys "{ENTER}"
          objShell.SendKeys "^v"
          WScript.Sleep 2500 
          objShell.SendKeys "^p"
          WScript.Sleep 2500 
          objShell.SendKeys "^p"
          WScript.Sleep 2200
          objShell.SendKeys "^a"
          WScript.Sleep 2200
      Next 
      objShell.SendKeys "^q"
      WScript.Sleep 5000
  Next
  MsgBox "No. Of TC's executed : " &amp; x-1
  WScript.Quit
  </code></pre>