51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1691|回复: 0
打印 上一主题 下一主题

聊聊selenium的webdriver的超时参数

[复制链接]
  • TA的每日心情
    无聊
    4 天前
  • 签到天数: 530 天

    连续签到: 2 天

    [LV.9]测试副司令

    跳转到指定楼层
    1#
    发表于 2019-1-4 15:44:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    本帖最后由 测试积点老人 于 2019-1-4 15:46 编辑

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



    超时参数

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

    1. /**
    2.    * An interface for managing timeout behavior for WebDriver instances.
    3.    */
    4.   interface Timeouts {

    5.     /**
    6.      * Specifies the amount of time the driver should wait when searching for an element if it is
    7.      * not immediately present.
    8.      * <p>
    9.      * When searching for a single element, the driver should poll the page until the element has
    10.      * been found, or this timeout expires before throwing a {[url=home.php?mod=space&uid=26824]@link[/url] NoSuchElementException}. When
    11.      * searching for multiple elements, the driver should poll the page until at least one element
    12.      * has been found or this timeout has expired.
    13.      * <p>
    14.      * Increasing the implicit wait timeout should be used judiciously as it will have an adverse
    15.      * effect on test run time, especially when used with slower location strategies like XPath.
    16.      *
    17.      * @param time The amount of time to wait.
    18.      * @param unit The unit of measure for {[url=home.php?mod=space&uid=21701]@code[/url] time}.
    19.      * @return A self reference.
    20.      */
    21.     Timeouts implicitlyWait(long time, TimeUnit unit);

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

    33.     /**
    34.      * Sets the amount of time to wait for a page load to complete before throwing an error.
    35.      * If the timeout is negative, page loads can be indefinite.
    36.      *
    37.      * @param time The timeout value.
    38.      * @param unit The unit of time.
    39.      * @return A Timeouts interface.
    40.      */
    41.     Timeouts pageLoadTimeout(long time, TimeUnit unit);
    42.   }
    复制代码
    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()只会找一遍指定元素,找不到就马上抛异常



    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是指外部资源加载完,而异步脚本执行完跟这个应该不是一回事。




    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-25 14:59 , Processed in 0.059888 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表