title: Selenium - Java Wait for page to load fails in test scripts
body: <p>I create test cases in Eclipse IDE using JAVA with some Selenium scripts.</p>
  
  <p>My Problem is that sometimes, Continuous Run of Test Cases produce error/failed test in the selenium.waitForPageToLoad("30000") method. I made a solution that the method will loop until a specific condition is met so I came to this code. BUT THIS DOESN'T WORK.</p>
  
  <p>This what happens: Run Junit Test > @Test1,2,3..n > page does not load @ Test n > execute next line code > failed test in @Test n > because Page does not load so the next scripts cannot be done (missing required elements in the page because it doesn't load).</p>
  
  <p>This what SUPPOSED to happen:Run Junit Test > @Test1,2,3..n >  page does not load @ Test n > wait for page to load until Specific condition is met (ex. Element X is already present in the page)> execute next line code > passed test in @Test n</p>
  
  <p>I need a Solution  that wait the Page to load until the element required for the next lines of scripts is present.</p>
  
  <p>THIS CODE DOESN'T WORK. I badly need your help. Thanks</p>
  
  <pre><code>//Wait for Page to Load until Expected Element is not Present   
  public void waitForPageToLoadElement(final String isElementPresent){
  
  boolean elementBoolean;
  do{
  selenium.waitForPageToLoad("30000");
  elementBoolean = selenium.isElementPresent(isElementPresent);
  if (elementBoolean==false){
  try{Thread.sleep(3000);}
  catch (Exception e) {
  //catch
  }}
  }
  while(elementBoolean==false);
  }
  //Wait for Page to Load until Expected Text is not Present
  public void waitForPageToLoadText(String isTextPresent){
  
  boolean elementBoolean;
  do{
  selenium.waitForPageToLoad("30000");
  elementBoolean = selenium.isTextPresent(isTextPresent);
  if (elementBoolean==false){
  try{Thread.sleep(3000);}
  catch (Exception e) {
  //catch
  }}
  }
  while(elementBoolean==false);
  
  }
  
  //Opens url until Expected Element is not Present
  public void openUrl(String url){
  
  boolean userNameBoolean, passwordBoolean;
  do {
  selenium.open(url);
  userNameBoolean = selenium.isElementPresent("id=loginForm:username");
  passwordBoolean = selenium.isElementPresent("id=loginForm:password");
  if (userNameBoolean==false &amp;&amp; passwordBoolean==false){
  try{Thread.sleep(3000);}
  catch (Exception e) {
  //catch
  }}
  }while (userNameBoolean==false &amp;&amp; passwordBoolean==false);
  
  }
  </code></pre>