title: Wait time out error in selenium-webdriver and phantomJS
body: <p>I am writing my automated test scripts using selenium-webdriver, phantomJS and mocha.</p>
  
  <p>My script file is javascript file by nature.</p>
  
  <p>I want to wait till an element() becomes completely visible. After it becomes visible, the element will be clicked.</p>
  
  <p>Let me explain in details:</p>
  
  <p>There are some menus and submenus. The menu is collapsible in nature. When I click on a menu, then its corresponding submenus are displayed.</p>
  
  <p>My following script first iterates(And clicks) through the menu and then iterates and (should be) clicking the submenu.</p>
  
  <pre><code>for(var iMajor = 2; iMajor &lt;= majorLinkLast ; iMajor++)
  {   
      (function(iMajor){
          majorMenuXPath = "//ul[contains(@id, 'side-menu')]/li["+iMajor+"]/a";
          if(iMajor != 2)
          {
              driver.findElement(By.xpath(majorMenuXPath)).click().then((function(iMajor){
                  for(var iMinor = 1; iMinor &lt;= minorSize[iMajor] ; iMinor++)
                  {
                      (function(iMajor, iMinor){
                          minorMenuXPath = "//ul[contains(@id, 'side-menu')]/li["+iMajor+"]/ul/li["+iMinor+"]/a";
                          driver.findElement(By.xpath(minorMenuXPath)).then(function(eleMinor){
                              driver.wait(function(){
                                      return eleMinor.isDisplayed();
                                  }, 20000).then(function(){
                                      eleMinor.isDisplayed().then(function(stat){
                                      console.log(stat);
                                  });
                              });
                          });
                      })(iMajor,iMinor)
                  }
              })(iMajor));
          } 
  
      })(iMajor)
  }
  </code></pre>
  
  <p>But I am getting message like this:</p>
  
  <pre><code>Track Revenue
  Track Revenue
  Track Revenue
  Track Revenue
  Track Revenue
  Track Revenue
  Campaigns
      1) View page by clicking menu
  
  
    2 passing (1m)
    1 failing
  
    1) TrackRevenue Click Menu Test View page by clicking menu:
       Error: timeout of 50000ms exceeded. Ensure the done() callback is being cal
  led in this test.
  </code></pre>
  
  <p>Why am I getting such output?</p>
  
  <p>The title should have been different.</p>
  
  <p>Please help.</p>