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.
-
1@Slanec You both are awesome. My arduous search has come to a happy conclusion.– Nathan LippiNov 19, 2012 at 23:58
Add a comment
|
1 Answer
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);
-
1
-
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'. Feb 4, 2013 at 23:32
-
-
A related question: FirefoxDriver webdriver.load.strategy unstable findelements getting elements from the wrong page Oct 21, 2015 at 11:25
-
As of 2016 according to this github.com/SeleniumHQ/selenium/issues/2873 it only works in Firefox <46 Nov 25, 2016 at 22:24