前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >聊聊selenium的webdriver的超时参数

聊聊selenium的webdriver的超时参数

作者头像
code4it
发布2018-09-17 15:14:56
1K0
发布2018-09-17 15:14:56
举报
文章被收录于专栏:码匠的流水账码匠的流水账

本文主要介绍下selenium的webdriver的超时参数。

超时参数

selenium-api-2.53.1-sources.jar!/org/openqa/selenium/WebDriver.java

代码语言:javascript
复制
 /**
   * 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);
  }

implicitlyWait

相当于设置全局的等待,在定位元素时,对所有元素设置超时时间,超出了设置时间则抛出异常。默认为0即不等待。

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. 没有设置implicitlyWait,则driver.findElement()只会找一遍指定元素,找不到就马上抛异常

scriptTimeout

设置异步脚本执行的超时时间,超出则抛异常。

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

用来设置页面完全加载的超时时间,完全加载即页面全部渲染。超过这个时间则抛出异常。默认为-1,即永不超时。

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. 这里是否包含异步脚本都执行完成呢,一般onload是指外部资源加载完,而异步脚本执行完跟这个应该不是一回事。

doc

  • selenium webdriver(5)—超时设置
  • WebDriver: Advanced Usage
  • webdriver-timeouts
  • WebDriverWait等设置等待时间和超时时间
  • The default value of timeouts on selenium webdriver
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2017-10-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 码匠的流水账 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 超时参数
  • implicitlyWait
  • scriptTimeout
  • pageLoadTimeout
  • doc
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档