zoukankan      html  css  js  c++  java
  • 什么是显示等待和隐式等待?

    智能等待 隐式等待:implicitly_wait()

    则默认每隔 0.5 秒检查一次,直到 10 秒后超时,如果在 10 秒内完成,则继续执行代码。 

    显式等待:WebDriverWait()

    WebDriverWait(driver,10).until(expected_conditions.presence_o f_element_located((By.ID,'email')))
    显示等待,等待邮箱输入框
    driver.implicitly_wait(3)
    隐式等待 3 秒

     

    什么是显示等待和隐式等待?

    显示等待就是有条件的等待
    隐式等待就是无条件的等待

    显式等待

    指定一个等待条件,和一个最长等待时间,程序会判断在等待时间内条件是否满足,如果满足则返回,如果不满足会继续等待,超过时间就会抛出异常

    input = wait.until(EC.presence_of_element_located((By.ID, 'q')))
    button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.btn-search')))
    print(input, button)

    隐式等待

    当使用了隐式等待执行测试的时候,如果WebDriver没有在DOM中找到元素,将继续等待,超出设定时间后则抛出找不到元素的异常,

    browser.implicitly_wait(10)  # 等待十秒加载不出来就会抛出异常,10秒内加载出来正常返回

    Implicit Wait in Selenium

    The Implicit Wait in Selenium is used to tell the web driver to wait for a certain amount of time before it throws a “No Such Element Exception”. The default setting is 0. Once we set the time, the web driver will wait for the element for that time before throwing an exception.

    Selenium Web Driver has borrowed the idea of implicit waits from Watir.

    In the below example we have declared an implicit wait with the time frame of 10 seconds. It means that if the element is not located on the web page within that time frame, it will throw an exception.

    To declare implicit wait in Selenium WebDriver:

    Implicit Wait syntax:

    driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);

    Consider Following Code:

    driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;

    Implicit wait will accept 2 parameters, the first parameter will accept the time as an integer value and the second parameter will accept the time measurement in terms of SECONDS, MINUTES, MILISECOND, MICROSECONDS, NANOSECONDS, DAYS, HOURS, etc.

    Explicit Wait in Selenium

    The Explicit Wait in Selenium is used to tell the Web Driver to wait for certain conditions (Expected Conditions) or maximum time exceeded before throwing “ElementNotVisibleException” exception. It is an intelligent kind of wait, but it can be applied only for specified elements. It gives better options than implicit wait as it waits for dynamically loaded Ajax elements.

    Once we declare explicit wait we have to use “ExpectedConditions” or we can configure how frequently we want to check the condition using Fluent Wait. These days while implementing we are using Thread.Sleep() generally it is not recommended to use

    In the below example, we are creating reference wait for “WebDriverWait” class and instantiating using “WebDriver” reference, and we are giving a maximum time frame of 20 seconds.

    Explicit Wait syntax:

    WebDriverWait wait = new WebDriverWait(WebDriverRefrence,TimeOut);
     
  • 相关阅读:
    记录第一次阿里云服务器部署java web工程的经历
    常用网站……
    根据ID获取CEdit的句柄实例
    (转)MFC中获得各个类的指针/句柄 ID的总结
    (转)DoDataExchange执行时机
    深入浅出Visual_C动态链接库(Dll)编程(宋宝华)----整理(word)
    (转)MFC的一些宏的整理 (DECLARE_DYNCREATE/IMPLEMENT_DYNCREATE)
    Socket 学习入门
    (转) 新的开始之Win7、CentOS 6.4 双系统 硬盘安装
    WIN7下使用VC2010调试uCOS-II 2.91
  • 原文地址:https://www.cnblogs.com/JacquelineQA/p/15587658.html
Copyright © 2011-2022 走看看