sequence

This article focuses on selenium webDriver timeout parameters.

Timeout parameter

The selenium – API – 2.53.1 – sources jar! /org/openqa/selenium/WebDriver.java

 /**
   * 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 A Timeouts interface.
     */
    Timeouts pageLoadTimeout(long time, TimeUnit unit);
  }Copy the code

implicitlyWait

This is equivalent to setting a global wait. When locating elements, a timeout is set for all elements and an exception is thrown if the timeout is exceeded. The default value is 0, meaning no wait.

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance. Without implicitlyWait, driver.findelement () looks only once for the specified element and throws an exception when it fails to find it

scriptTimeout

Example Set the timeout period for asynchronous script execution. If the timeout period is exceeded, an exception is thrown.

The amount of time, in milliseconds, this session should wait for asynchronous scripts to finish executing. If set to 0, then the timeout will not fire until the next event loop after the script is executed. This will give scripts that employ a 0-based setTimeout to finish.

pageLoadTimeout

Used to set the timeout for a page to be fully loaded, i.e. rendered. Any longer than that, an exception is thrown. The default value is -1, that is, it never times out.

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.

So if you have an asynchronous script that’s finished executing, the onload is the external resource that’s finished loading, and the asynchronous script that’s finished executing is not the same thing.

doc

  • Selenium WebDriver (5) — Timeout Settings
  • WebDriver: Advanced Usage
  • webdriver-timeouts
  • WebDriverWait Sets the waiting time and timeout period
  • The default value of timeouts on selenium webdriver