Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium WebDriver go to page without waiting for page load

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.

like image 636
Jackson Avatar asked Jul 12 '12 15:07

Jackson


1 Answers

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);
like image 55
Petr Janeček Avatar answered Sep 18 '22 18:09

Petr Janeček