To synchronize between content execution and application, we have to hold up subsequent to performing fitting activities. Let us take a gander at the approaches to accomplish the equivalent.
Thread.Sleep
Thread.Sleep is a static pause and it's anything but a decent method to use in contents as it is rest without condition.
Thread.Sleep(1000); //Will wait for 1 second.
Explicit Waits
An 'unequivocal pause,' trusts that a specific condition will happen before continuing further. It is for the most part utilized when we need to snap or follow up on an article once it is obvious.
WebDriver driver = new FirefoxDriver();
driver.get("Enter an URL"S);
WebElement DynamicElement =
(new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("DynamicElement")));
Implicit Wait
Certain hold up is utilized in situations where the WebDriver can't find an article promptly as a result of its inaccessibility. The WebDriver will hang tight for a predetermined verifiable hold up time and it won't attempt to discover the component again during the predefined timeframe.
When the predefined time limit is crossed, the webDriver will attempt to look the component indeed for one final time. Upon progress, it continues with the execution; upon disappointment, it tosses special case.
It is a sort of worldwide hold up which implies the hang tight is pertinent for the whole driver. Henceforth, hardcoding this hang tight for longer timespans will hamper the execution time.
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("Enter an URL");
WebElement DynamicElement = driver.findElement(By.id("DynamicElement"));
Fluent Wait
A FluentWait case characterizes the most extreme measure of time to trust that a condition will occur, just as the recurrence with which to check the presence of the article condition.
Let us state we will 60 seconds for a component to be accessible on the page, however we will check its avilable once in at regular intervals.
Wait wait =
new FluentWait(driver).withTimeout(60, SECONDS).pollingEvery(10, SECONDS).ignoring(NoSuchElementException.class);
WebElement dynamicelement = wait.until(new Function<webdriver,webElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("dynamicelement"));
}
});
