title: In Java, best way to check if Selenium WebDriver has quit
body: <p>I need to check a collection of Page Objects to see, for each one, if quit() has been called on its WebDriver.</p>
  
  <p>I've written the following method to check a WebDriver's state:</p>
  
  <pre><code>public static boolean hasQuit(WebDriver driver) {
          try {
              driver.getTitle();
              return false;
          } catch (SessionNotFoundException e) {
              return true;
          }
  }
  </code></pre>
  
  <p>Here's the problem: I don't like having to throw and catch an exception to discover the truth of a boolean, but it seems I have no choice since the <b><a href="http://selenium.googlecode.com/git/docs/api/java/index.html" rel="noreferrer">WebDriver API</a></b> doesn't provide a method to check if the driver has quit.</p>
  
  <p><p>So my question is, <b><i>is there a better way to check if a WebDriver has quit?</i></b></p>
  
  <p>I found a similar (and more general) question <b><a href="https://stackoverflow.com/questions/11674254/selenium-webdriver-sessionid-or-check-if-all-browser-windows-are-closed">here</a></b>, but the question did not have any code that had been tried, and the only answer was to always set the WebDriver to null after quiting (which I don't necessarily have control over).</p>