0% found this document useful (0 votes)
61 views2 pages

Fluent Wait

This document discusses different types of waits that can be used in Selenium WebDriver testing - implicit waits and explicit waits. It describes the FluentWait and WebDriverWait classes that implement explicit waits, their methods, and how to configure timeouts and polling intervals. An example shows setting up a FluentWait to wait for an element on an Amazon page with a timeout of 10 seconds and polling every 500 milliseconds.

Uploaded by

Passion 4 Oracle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views2 pages

Fluent Wait

This document discusses different types of waits that can be used in Selenium WebDriver testing - implicit waits and explicit waits. It describes the FluentWait and WebDriverWait classes that implement explicit waits, their methods, and how to configure timeouts and polling intervals. An example shows setting up a FluentWait to wait for an element on an Amazon page with a timeout of 10 seconds and polling every 500 milliseconds.

Uploaded by

Passion 4 Oracle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package webdrivermethods;

import java.time.Duration;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;

import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
* Wait(I) - 2 Types (Implicit Wait & Explicit Wait)
* public until(ExpectedConditions isTrue) --> ExpectedConditions(C) &
ExpectedCondition(I)
*
* 1) Implicit Wait
* 2) Explicit Wait (2 types: FluentWait(C) & WebDriverWait(C))
* FluentWait(C) contains all methods & WebDriverWait(C) contains its constructor.
*
* public class FluentWait implements Wait
* 1) public FluentWait withTimeout(Duration timeout) --> Sets how long to wait for
the evaluated condition to be true.
* 2) public FluentWait withMessage(final String message) --> Sets displayed the
message when time expires.
* 3) public FluentWait pollingEvery(Duration interval) --> Sets how often the
condition should be evaluated.
* 4) public FluentWait ignoreAll(Collection types) --> ignore all exception
mention in this Collection types.
* 5) public FluentWait ignoring(FirstException.class, SecondException.class ....)
*
* public class WebDriverWait extends FluentWait
*
* @author Dharmik Mehta
*/
public class WaitInSelenium {

public void explicitWaitWithPolling() {


System.setProperty("webdriver.chrome.driver", "D:\\Jars\\ChromeDriver\\
chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
// Configure Implicit Wait
// driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

// Configure Explicit Wait


FluentWait wait = new FluentWait(driver);
wait.withTimeout(Duration.ofSeconds(10));
wait.pollingEvery(Duration.ofMillis(500));
wait.withMessage("Explict Waiting....");
wait.ignoring(TimeoutException.class);

// WebDriverWait
// WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds,
sleepInMillis);
driver.get("https://www.amazon.in/");
driver.manage().window().maximize();
driver.findElement(By.xpath("//a[contains(text(),
'Mobiles')]")).click();
//a[@href="/mobile-phones/b/?
ie=UTF8&node=1389401031&ref_=nav_cs_mobiles"]
//a[@href='/mobile-phones/b/?
ie=UTF8&node=1389401031&ref_=nav_cs_mobiles']
driver.navigate().back();

wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//
a[contains(text(), \"Today's Deals\")]")));
driver.findElement(By.xpath("//a[contains(text(), \"Today's
Deals\")]")).click();
driver.navigate().back();
// driver.quit();
}

public static void main(String[] args) {


new WaitInSelenium().explicitWaitWithPolling();
}
}

You might also like