title: How to Stop the page loading in firefox programmatically?
body: <p>I am running several tests with WebDriver and Firefox. </p>
  
  <p>I'm running into a problem with the following command:</p>
  
  <p><code>WebDriver.get(www.google.com);</code></p>
  
  <p>With this command, WebDriver blocks till the onload event is fired. While this can normally takes seconds, it can take hours on websites which never finish loading.</p>
  
  <p>What I'd like to do is stop loading the page after a certain timeout, somehow simulating Firefox's stop button.</p>
  
  <p>I first tried execute the following JS code every time that I tried loading a page:</p>
  
  <pre><code>var loadTimeout=setTimeout(\"window.stop();\", 10000);
  </code></pre>
  
  <p>Unfortunately this doesn't work, probably because :</p>
  
  <blockquote>
    <p>Because of the order in which scripts are loaded, the stop() method cannot stop the document in which it is contained from loading <a href="https://github.com/detro/ghostdriver" rel="noreferrer">1</a></p>
  </blockquote>
  
  <p>UPDATE 1: I tried to use SquidProxy in order to add connect and request timeouts, but the problem persisted.</p>
  
  <p>One weird thing that I found today is that one web site that never stopped loading on my machine (FF3.6 - 4.0 and Mac Os 10.6.7) loaded normally on other browsers and/or computers.</p>
  
  <p>UPDATE 2: The problem apparently can be solved by telling Firefox not to load images. hopefully, everything will work after that...</p>
  
  <p>I wish WebDriver had a better Chrome driver in order to use it. Firefox is disappointing me every day!</p>
  
  <p>UPDATE 3: Selenium 2.9 added a new feature to handle cases where the driver appears to hang. This can be used with <code>FirefoxProfile</code> as follows:</p>
  
  <pre><code>FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("web");
  firefoxProfile.setPreference("webdriver.load.strategy", "fast");
  </code></pre>
  
  <p>I'll post whether this works after I try it.</p>
  
  <p>UPDATE 4: at the end none of the above methods worked. I end up "killing" the threads that are taking to long to finish. I am planing to try <a href="https://github.com/detro/ghostdriver" rel="noreferrer">Ghostdriver</a> which is a Remote WebDriver that uses PhantomJS as back-end. PhantomJS is a headless WebKit scriptable, so i expect not to have the problems of a real browser such as firefox. For people that are not obligate to use firefox(crawling purposes) i will update with the results </p>
  
  <p>UPDATE 5: Time for an update. Using for 5 months the ghostdriver 1.1 instead FirefoxDriver i can say that i am really happy with his performance and stability. I got some cases where we have not the appropriate behaviour but looks like in general ghostdriver is stable enough. So if you need, like me, a browser for crawling/web scraping purposes  i recomend you use ghostdriver instead firefox and xvfb which will give you several headaches...</p>