15

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?

  • 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
  • 1
    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
18

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

4

Apparently there is a timeout. It is 30 minutes long.

SEVERE: Timed out waiting for page load.
Command duration or timeout: 1800.01 seconds
Build info: version: '2.40.0', revision: 'fbe29a9', time: '2014-02-19 20:55:11'
System info: host: 'PurpleMimosa.local', ip: '10.11.11.131', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.2', java.version: '1.7.0_51'
Session ID: 11e6b0f4-15f2-7d48-8dbc-2176def7e41f
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=29.0.1}]
  • 1
    Welcome to SQA, Plastiq! A number of other folks have said there is no timeout by default, but that you can set one. Could you elaborate on how you produced this, and how we might show that the timeout isn't being set (and is therefore the default)? – corsiKa May 22 '14 at 22:24
  • 1
    @corsiKa: Apparently a number of other folks are misinformed... I have also obtained a timeout after clicking a link that waited over 30 minutes to load. How to produce this? How to show that the timeout isn't being set? Start with a clean installation, don't manually set the timeout, and try to load a page that takes an hour to come up. simple! :) – Darren Ringer Sep 21 '15 at 19:27
3

Welcome to SQA, saikrishna. According to StackOverflow question, the timeout is 30 seconds.

  • 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
  • 3
    A default timeout of 30 Seconds is the Selenium RC API, not the WebDriver one. – Ardesco Feb 9 '12 at 12:20
0

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

  • Sorry for the edit; Modified the code, as you suggested. – Bharat Mane Sep 14 '17 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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