Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

Types of Explicit Wait in Selenium webdriver (Java)?

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..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are following waits:

FluentWait

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"));
  }

  });

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

Types of Expected Conditions: 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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...