फ्लुएंट वेट एक डायनामिक वेट है जो ड्राइवर को एक शर्त के लिए रुकने के लिए मजबूर करता है जिसे एक फ्रीक्वेंसी पर जांचा जाता है इससे पहले कि एक एक्सेप्शन फेंका जाए। एलिमेंट को DOM में लगातार नहीं बल्कि नियमित समय अंतराल पर खोजा जाता है।
उदाहरण के लिए, यदि वेट 5 सेकंड के लिए है, तो FluentWait DOM को नियमित अंतराल पर मॉनिटर करता है (पोलिंग समय के दौरान परिभाषित)। FluentWait में, शर्तों के आधार पर कस्टमाइज़्ड वेट मेथड्स बनाने की आवश्यकता होती है।
सिंटैक्स -
Wait<WebDriver> w = new FluentWait< WebDriver >(driver) .withTimeout (10, SECONDS) .pollingEvery (2, SECONDS) .ignoring (NoSuchElementException.class)
उदाहरण
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.support.ui.Wait; import org.openqa.selenium.support.ui.FluentWait; public class Fluentwt { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); //प्रत्येक एलिमेंट पर लागू सेकंड में इम्प्लिसिट वेट driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); //Coding Ground लिंक पर क्लिक करना driver.findElement(By.xpath("//span[text()=’Coding Ground’]")).click(); // फ्लुएंट वेट घोषणा Wait<WebDriver> w = new FluentWait<WebDriver>(driver).withTimeout (Duration.ofSeconds(30)) .pollingEvery(Duration.ofSeconds(3)).ignoring( NoSuchElementException.class); WebElement fl = w.until(new Function<WebDriver, WebElement>() { // फ्लुएंट वेट के लिए कस्टमाइज़्ड शर्त public WebElement apply(WebDriver driver) { if (driver.findElement(By.xpath("[//img[@title=’Whiteboard’")) .isDisplayed()) { return true; }else { return null; } } }); driver.quit(); } }