12

I'm translating some Selenium RC tests to Selenium WebDriver using the python api. In Selenium WebDriver, I'm noticing that driver.get( 'http://...' ) seems to wait for the entire page to load before proceeding. Is there a way to not wait for a page to load? Some of the pages I'm requesting have a lot of external resources that can potentially take a long time to load. I'd rather wait for elements on the DOM to be present than wait for everything to load. Some of my tests seem to take twice as long in WebDriver because of this.

Jackson
  • 607
  • 2
  • 6
  • 20

1 Answers1

13

Yes and no. As of Selenium 2.24.1, the support for this is only in Firefox - you have to run it in a special "mode":

FirefoxProfile fp = new FirefoxProfile();
fp.setPreference("webdriver.load.strategy", "unstable");
WebDriver driver = new FirefoxDriver(fp);

You can even set the timeout if you want to. This method fails in any browser other than Firefox and does nothing in Firefox without the unstable strategy:

driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
Petr Janeček
  • 37,768
  • 12
  • 121
  • 145
  • 1
    Thanks. Answered my question completely. – Jackson Jul 13 '12 at 14:16
  • Also, when polling for objects on your expected page, if you use findElements() instead of findElement(), you can avoid null pointers by using something like 'if findElements()=0 keep trying'. – djangofan Feb 04 '13 at 23:32
  • What is the Python equivalent code for page load timeouts ? – The_Diver Aug 28 '15 at 11:37
  • A related question: [FirefoxDriver webdriver.load.strategy unstable findelements getting elements from the wrong page](http://stackoverflow.com/questions/20954605/firefoxdriver-webdriver-load-strategy-unstable-findelements-getting-elements-fro) – Dawngerpony Oct 21 '15 at 11:25
  • As of 2016 according to this https://github.com/SeleniumHQ/selenium/issues/2873 it only works in Firefox <46 – lmiguelmh Nov 25 '16 at 22:24