Explain Fluent Wait In Selenium Webdriver
Posted By : Mohd Sheemal | 13-Jun-2018
Fluent wait is the seperate class in selenium webdriver and using this class we can wait for a specific condition until it is not satisfied so we have already know explicit wait also having lots of preconditions that are more than sufficient but using fluent wait you can customised specific condition.
In f
If you want to change the po
- Fluent wait is a class and is the part of org.openqa.selenium.support.ui package.
- It is an implementation of wait interface.
- Each familiar hold up occurrence characterizes the greatest measure of time to sit tight for a condition and we can give the recurrence with which to check the condition.
- We can also ignore any exception while polling element such as No such element exception in selenium.
Example :
import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.FluentWait; import com.google.common.base.Function; public class FluentWaitDEmo { public static void main(String[] args) throws InterruptedException { // Start browser WebDriver driver = new ChromeDriver(); // Maximize browser driver.manage().window().maximize(); // Start the application driver.get("url here"); // Click on timer so clock will start driver.findElement(By.xpath("Write xpath")).click(); // Create object of FluentWait class and pass webdriver as input FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver); // It should poll webelement after every single second wait.pollingEvery(1, TimeUnit.SECONDS); // Max time for wait- If conditions are not met within this time frame then it will fail the script wait.withTimeout(10, TimeUnit.SECONDS); // we are creating Function here which accept webdriver and output as WebElement- WebElement element = wait.until(new Function<WebDriver, WebElement>() { // apply method- which accept webdriver as input @Override public WebElement apply(WebDriver arg0) { // find the element WebElement ele = arg0.findElement(By.xpath("Write xpath")); // Will capture the inner Text and will compare will WebDriver // If condition is true then it will return the element and wait will be over if (ele.getAttribute("innerHTML").equalsIgnoreCase("WebDriver")) { System.out.println("Value is >>> " + ele.getAttribute("innerHTML")); return ele; } // If condition is not true then it will return null and it will keep checking until condition is not true else { System.out.println("Value is >>> " + ele.getAttribute("innerHTML")); return null; } } }); // If element is found then it will display the status System.out.println("Final visible status is >>>>> " + element.isDisplayed()); }
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Mohd Sheemal
Mohd Sheemal is a Bright QA Engineer. He has a good knowledge over Selenium.