title: Selenium and Angularjs wait until to do some actions
body: <p>I'm using selenium to test AngularJS application. I'm facing issue that I cannot do any actions on the page until it loads fully. I can put Thread.sleep(), but this is not good solution as I know. There many ways to wait until page will be loaded(I google it), but I think I tried them all and still no luck. In my applications when go to webpage, everything looks loaded(from visual perspective), but I can not do any activities until full page loads(around 1 sec).
  Can you guys share your implementation how you did it that is actually works</p>
  
  <p>Thank you</p>
  
  <p>My code:</p>
  
  <pre><code>public By ngWait(final By by) {
      return new FluentBy() {
          @Override
          public void beforeFindElement(WebDriver driver) {
              driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
              ((JavascriptExecutor) driver).executeAsyncScript("var callback = arguments[arguments.length - 1];" +
                      "angular.element(document.body).injector().get('$browser').notifyWhenNoOutstandingRequests(callback);");
              super.beforeFindElement(driver);
          }
  
          @Override
          public List&lt;WebElement&gt; findElements(SearchContext context) {
              return by.findElements(context);
          }
  
          @Override
          public WebElement findElement(SearchContext context) {
              return by.findElement(context);
          }
  
          @Override
          public String toString() {
              return "ngWait(" + by.toString() + ")";
          }
      };
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/yEzxA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yEzxA.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/lwS5g.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lwS5g.jpg" alt="enter image description here"></a></p>