Selenium webdriver (Java) 中的显式等待类型? [英] Types of Explicit Wait in Selenium webdriver (Java)?

查看:31
本文介绍了Selenium webdriver (Java) 中的显式等待类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Selenium webdriver (Java) 中的显式等待中存在哪些类型的等待?Explicit Wait 中是否有任何类型?如果是,请详细说明..

What are the types of waits present in the Explicit Wait in Selenium webdriver (Java)? Is there any types in Explicit Wait? if so please elaborate..

推荐答案

有以下等待:

FluentWait

这是特殊的等待,您可以在其中设置等待特定条件的时间,以及检查条件的频率,例如.等待 10 秒,每 1 秒检查一次,如果您预计此异常会发生一段时间,则忽略NoSuchElementExceptions"异常.

This is special wait where You can set time to wait for a certain condition, as well as the frequency with which to check the condition like eg. wait for 10s and check every 1s, and ignore "NoSuchElementExceptions" exception, if You anticipate that this exception will happen for some time.

  Wait wait = new FluentWait(driver)
    .withTimeout(30, SECONDS)
    .pollingEvery(5, SECONDS)
    .ignoring(NoSuchElementException.class);

  WebElement foo = wait.until(new Function() {
    public WebElement apply(WebDriver driver) {
    return driver.findElement(By.id("foo"));
  }

  });

显式等待这是一种等待,您可以将其设置为等待您可能喜欢的任何条件.通常,您可以使用一些预构建的 ExpectedConditions

Explicit wait It is kind of wait where You can set it up to wait for any condition you might like. Usually, you can use some of the prebuilt ExpectedConditions

预期条件的类型:https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/support/ui/ExpectedConditions.java

WebDriverWait wait = new WebDriverWait(driver, 10);

    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));

隐式等待等待元素,直到初始化对象时抛出异常,并通过整个会话定义

Implicit wait wait for element, until exception is thrown while initialising object, and its defined through entire session

 WebDriver driver = new FirefoxDriver();
 driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
 driver.get("http://...");
 WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));

页面加载超时页面加载需要多长时间:

PageLoadTimeout How long it will until page is loaded:

 driver.manage().timeouts().pageLoadTimeout(100, SECONDS);

SetScriptTimeout

如果您有异步脚本.在抛出错误之前等待异步脚本完成执行的时间.

If you have asynch scripts. Time to wait for an asynchronous script to finish execution before throwing an error.

driver.manage().timeouts().setScriptTimeout(100,SECONDS);

这篇关于Selenium webdriver (Java) 中的显式等待类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆