I want to implement Fluent Wait in my test script but I am new to Selenium and don t know much about Waits Can anyone please help

0 votes
I want to implement Fluent Wait in my test script, but I am new to Selenium and don't know  much about Waits. Can anyone please help?
Jul 23, 2019 in Selenium by Indu
1,834 views

1 answer to this question.

0 votes

Hey Indu, Fluent wait is a class which we can use to wait until specific conditions are met. In Fluent wait, we can change the default polling period based on our requirement. Each fluent wait instance defines the maximum amount of time to wait for a condition and we can give the frequency with which to check the condition

We can also ignore any exception while polling element such as NoSuchElement exception in Selenium. Following example shows how you can use Fluent Wait:

package fluentWaitTest;
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 {

          WebDriver driver = new ChromeDriver();
          driver.manage().window().maximize();
          driver.get("https://www.edureka.co");

          driver.findElement(By.xpath("//button[text()=''Sign Up']")).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) 
               {
                    WebElement element = arg0.findElement(By.xpath("//p[@id='demo']"));

                    // If condition is true then it will return the element and wait will be over
                    if (element.getAttribute("innerHTML").equalsIgnoreCase("WebDriver")) 
                    {
                       System.out.println("Value is >>> " + element.getAttribute("innerHTML"));
                       return element;
                     }

                    // 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());
     }
}
answered Jul 23, 2019 by Abha
• 28,140 points

This Type of Fluent Wait is now Deprecated Friends.

So I found the best resource for the current usage for fluent wait. Here in the below Selenium's Official Link:

https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/support/ui/FluentWait.html
Thanks a lot, man!

Related Questions In Selenium

0 votes
1 answer

I am not able to generate extent report with screenshot in selenium cucumber java .. Please help me out

Hello @kanikahans, You need to define Extent Report ...READ MORE

answered Aug 24, 2020 in Selenium by Niroj
• 82,880 points
7,796 views
0 votes
1 answer

i cannot add chromedriver to my path on mac.what should i do? can you tell me full procedure? i am new to selenium.

Hello @Divya, You can refer this regarding your ...READ MORE

answered Nov 25, 2020 in Selenium by Niroj
• 82,880 points
663 views
0 votes
1 answer

Impilicit wait vs Explicit wait vs Fluent wait

Implicit wait: Your telling the WebDriver the ...READ MORE

answered Apr 14, 2018 in Selenium by king_kenny
• 3,710 points
4,008 views
+1 vote
4 answers

Need to wait until page is completely loaded - Selenium WebDriver

You can try something like -  new WebDriverWait(firefoxDriver, ...READ MORE

answered Dec 21, 2019 in Selenium by Robin
63,307 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,619 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,572 views
0 votes
2 answers

Can anyone help me that how to run Selenium WebDriver test cases in Chrome?

You first need to download chrome driver ...READ MORE

answered Aug 26, 2019 in Selenium by Abha
• 28,140 points
1,660 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP