Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I am using Selenium 2. I have loaded the page using Get command in WebDriver class which is in the package org.openqa.selenium. My question is that what is Selenium's default timeout for page loading?

share|improve this question
    
Are you trying to ask how long it normally takes for Selenium to load a page? –  user246 Feb 8 '12 at 11:17
    
yes, exactly, whats the default time for page to load, In the Api, it is explained that get method is blocked until the load is complete and if the page is not loaded it does not throw any exception –  saikrishna Feb 8 '12 at 11:48
1  
wont that depend on what's on the page ? A 'hello world' page is going to load faster than a page with 1000 elements on it –  Phil Kirkham Feb 8 '12 at 13:21
    
if the page is not loaded with in the specific time limit it should throw some exception, whats the default time for page to get loaded, if it is not loaded with in the default time, will it throw any exception like, TimeoutException –  saikrishna Feb 8 '12 at 13:33
add comment

3 Answers

The default WebDriver setting for timeouts is never. WebDriver will sit there forever waiting for the page to load.

The following timeouts are available:

  /**
   * An interface for managing timeout behavior for WebDriver instances.
   */
  interface Timeouts {

    /**
     * Specifies the amount of time the driver should wait when searching for an element if it is
     * not immediately present.
     * <p/>
     * When searching for a single element, the driver should poll the page until the element has
     * been found, or this timeout expires before throwing a {@link NoSuchElementException}. When
     * searching for multiple elements, the driver should poll the page until at least one element
     * has been found or this timeout has expired.
     * <p/>
     * Increasing the implicit wait timeout should be used judiciously as it will have an adverse
     * effect on test run time, especially when used with slower location strategies like XPath.
     * 
     * @param time The amount of time to wait.
     * @param unit The unit of measure for {@code time}.
     * @return A self reference.
     */
    Timeouts implicitlyWait(long time, TimeUnit unit);

    /**
     * Sets the amount of time to wait for an asynchronous script to finish execution before
     * throwing an error. If the timeout is negative, then the script will be allowed to run
     * indefinitely.
     * 
     * @param time The timeout value.
     * @param unit The unit of time.
     * @return A self reference.
     * @see JavascriptExecutor#executeAsyncScript(String, Object...)
     */
    Timeouts setScriptTimeout(long time, TimeUnit unit);

    /**
     * Sets the amount of time to wait for a page load to complete before throwing an error.
     * If the timeout is negative, page loads can be indefinite.
     *
     * @param time The timeout value.
     * @param unit The unit of time.
     * @return
     */
    Timeouts pageLoadTimeout(long time, TimeUnit unit);
  }

You can tweak the timeouts by setting driver.manage().timeouts().pageLoadTimeout()

More information here:

Selenium Wiki

share|improve this answer
    
Thanks for the answer, I did not know that! –  Sam Woods Feb 15 '12 at 18:12
1  
There are 3 kinds of timeouts. Page load timeout != implicit wait timeout. Page load timeout is limited by default‌​. I wish I could downvote this answer –  Andrey Botalov Apr 8 '13 at 12:13
    
Your right, I've conflated implicitly wait with page load timeout, time to update the answer. –  Ardesco Apr 8 '13 at 14:05
add comment

Welcome to SQA, saikrishna. According to http://stackoverflow.com/a/5504375/100464, the timeout is 30 seconds.

share|improve this answer
3  
You may modify that value with the following Java code: driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); –  Scott Feb 8 '12 at 20:05
    
Thanks scott for the useful post –  saikrishna Feb 9 '12 at 5:39
1  
A default timeout of 30 Seconds is the Selenium RC API, not the WebDriver one. –  Ardesco Feb 9 '12 at 12:20
add comment

There is no timeout, as others have said. However, the ImplicitlyWait() that has been suggested is actually for page elements to appear. For page loading you want to set the "page load" timeout instead. This will then interrupt your get() call after that many milliseconds.

If you're using Java, you use setScriptTimeout().

If using PHP I added this function to the end of WebDriver.php and it works for me:

/**
 * Set wait for a page to load.
 * 
 * @param Number $waitTimeout Number of milliseconds to wait.
 */
public function setPageLoadTimeout($waitTimeout) {
    $request = $this->requestURL . "/timeouts";        
    $session = $this->curlInit($request);
    $args = array('type'=>'page load', 'ms' => $waitTimeout);
    $jsonData = json_encode($args);
    $this->preparePOST($session, $jsonData);
    curl_exec($session);        
}

Reference: http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/timeouts

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.