title: Selenium: How to make the web driver to wait for page to refresh before executing another test
body: <p>I am writing Test Cases using Selenium web Driver in TestNG and I have a scenario where I am running multiple tests sequentially (refer below)</p>
  
  <pre><code>@Test(priority =1)
  public void Test1(){
  }
  @Test(priority =2)
  public void Test2(){ 
  }
  </code></pre>
  
  <p>Both Tests are AJAX calls where a Dialog box opens, tests executes, then dialog box closes and then a notification message appears on top of page and <strong>after each successful test the page refreshes</strong>.</p>
  
  <p><strong>The problem is:</strong> Test2 do not wait for the page to refresh/reload. Suppose when Test1 gets successfully completed, Test2 will start before page refresh (ie it opens the dialog box, executes scenarios etc..) meanwhile the page refreshes (which was bound to happen after successful execution of Test1 ). Now since the page refreshes, the diaog box opened due to Test2 is no longer present and then Test2 fails.</p>
  
  <p>(Also, I do not know how long it will take to refresh the page. Therefore, <strong>I do not want to use Thread.sleep(xxxx) before executing Test2</strong>)</p>
  
  <p>Also, I don't think </p>
  
  <pre><code>driver.navigate().refresh()
  </code></pre>
  
  <p>will solve my problem by putting it before Test2 as in that case my page will get refreshed twice. The problem is the refresh that is happening through the code (which is uncertain as it may take 1 sec or 3 sec or 5 sec)</p>