Implicit, Explicit & Fluent Wait in Selenium WebDriver

Implicit Wait vs Explicit Wait

Implicit Wait

Implicit Wait will let Selenium WebDriver to wait for a certain amount of time, before throwing the exception that it cannot find the element on the web page.

Note: The Implicit Wait will be in place, when the browser is opened. This means, that any search for elements on the page could take the time the Implicit Wait is set for.

WebDriver driver = new FirefoxDriver();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get("myURL");

WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));

Explicit Wait

It is more extendable in the means that you can set it up to wait for any condition you might like. Usually, you can use some of the pre-built Expected Conditions to wait for elements to become clickable, visible, invisible, etc.

driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait()

WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);

element = wait.until(ExpectedConditions.visibilityOfElementLocated(by));

Fluent Wait

Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configure the wait to ignore specific types of exceptions while waiting, such as NoSuchElementExceptions when searching for an element on the page.

FluentWait  wait = new FluentWait(driver).withTimeout(timeOutInSeconds,TimeUnit.SECONDS)
           .pollingEvery(200,TimeUnit.MILLISECONDS)
           .ignoring(NoSuchElementException.class);

element = (WebElement) wait.until(ExpectedConditions.visibilityOfElementLocated(by));

 


About the course

NPN Training is counted among the top ten Selenium Training in Bangalore for providing the best Selenium training in Bangalore. Our selenium course content and syllabus is designed according to the industry requirement to accomplish everyone’s career goal.

 

 

Related Post
Selenium Grid – Test execution in Cluster (P... In this post, we will discuss about the configuration of Hub & Node(s) with Options. Configure Hub To configure the Hub, please follow the below...

Pradeep

M.r Pradeep is QA expert working as a Research Analyst at NPN Training. He is having 12 years of experience in Quality Assurance with extensive of 4 years in Automation experience (Selenium, UFT, Rest Assured, Jmeter & Soap UI). He has helped the peers/students to understand and learn Automation with Selenium and API automation with Rest Assured with Hands-On approach.