title: Selenium: How to implement pageLoadTimeout() on navigated pages that are infinitely loading
body: <p>The page I am testing, it's loading forever due to the slow network(or Internet censorship, some of the resources are bound to fail loading). However most of elements of the page are present within 1 second. </p>
  
  <p>Since Selenium won't have an element clicked until the page's fully loaded, I want to use pageLoadTimeout() to stop the page from loading after 5 seconds and then handle the timeout and do something on the page. And the code works for the page which I specified in <em>get(url)</em>.</p>
  
  <pre><code>    try {
          driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
          driver.get(url);
      }
      catch (TimeoutException e){
      }
      finally {
          driver.findElement(By.xpath("xpath here")).click();
      }
  </code></pre>
  
  <p>However this won't work if you're trying to click a link and then be navigated to a new page. You're will soon get</p>
  
  <blockquote>
    <p>org.openqa.selenium.TimeoutException</p>
  </blockquote>
  
  <p>because the code above didn't handle this new page's timeout exception. Then I'll have to add another try-catch-finally to prevent this new page from  infinitely loading. This will get trickier if there're a lot of links you have to go thru before you are actually reaching the page you wanna test.</p>
  
  <p>Does anyone has a solution to this? </p>