• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Advance Selenium / How to use Implicit wait in Selenium Webdriver

How to use Implicit wait in Selenium Webdriver

June 15, 2020 by Mukesh Otwani 26 Comments

Selenium

This guide will help you to understand implicit wait in Selenium Webdriver and implementation as well. If you have ever worked on any automation tool then you must be aware of Sync issues in the script.

It is one of the biggest pain for an automation engineer to handle sync issues between elements.

Sometimes an application will not able to load elements due to the below issues.

  • Network issue
  • Application issues
  • Browser stopping JavaScript call.

And so on.

By default, Selenium will not wait for an element once the page load completes. It checks for an element on the page then it performs some operation based on your script but if the element is not present then it throws NoSuchElement Exception.

 

 

This is one of the interview questions that what is the default timeout in Selenium is.

Answer- The default timeout is ZERO.

 

I have listed down some most frequent exception of Selenium. I hope it will help you.

Frequently faced exception is Selenium Webdriver

 

If you are not sure how to handle exception then the below post will help you.

How to handle exception in Selenium Webdriver

 

Our main intention to use Implicit wait in selenium is to instruct Webdriver that waits for a specific amount before throwing an exception.

I will highly recommend using implicit wait in your every selenium script or if u have created framework then add the same in BaseClass or Utility

Note- Implicit wait in selenium webdriver will be applicable throughout your script and will works on all elements in the script once your specified implicit wait. It is also known as Global wait

 

Syntax of Implicit wait in selenium webdriver

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


 

Here in above example, I have used TimeUnit as seconds but you have so many options to use

Seconds, Minutes, Days, Hours, Microsecond, Milliseconds, and so on check the below screenshot for more information.

 

Implicit wait in Selenium

 

 

Once you move forward, you will get to know some more Timeout in Selenium like

Page load timeout in Selenium

Script load timeout in Selenium

Implicit wait in selenium Webdriver (Current reading)

Explicit wait in Selenium

Fluent wait in Selenium

Do not confuse with these exceptions because each of this having different usage.

 

Complete program with usage of implicit wait in selenium webdriver



import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;


public class VerifyTitle

{

                @Test

                public void verifySeleniumTitle()

                {

                                WebDriver driver=new FirefoxDriver();

                                driver.manage().window().maximize();

                                driver.get("http://www.learn-automation.com");

                                // Specify implicit wait of 30 seconds                                   
                                 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

                              // No login id is present on Webpage so this will fail our script.
                                driver.findElement(By.id("login")).sendKeys(" Selenium Webdriver");

                }

}


 

Console- The above script will fail because no login id is present on the page but it will wait for max 30 seconds before throwing an exception.

 

implicit wait in Selenium webdriver

Note- This is the max time so if any element is coming before 30 seconds it will move to next element.

Filed Under: Advance Selenium, Wait in Selenium Tagged With: implicit wait in Selenium

Reader Interactions

Comments

  1. Abhinav says

    October 30, 2020 at 5:52 AM

    while iam trying to run my java application in eclipse iam getting an error saying that “could not load main class” . can you please help me out with this.

    Reply
    • Mukesh Otwani says

      October 30, 2020 at 10:06 AM

      Hi Abhinav,

      Are you using @Test annotation from TestNG/JUnint? If not, then you need to use main method to execute your code

      Reply
  2. Siddharth Barthwal says

    October 15, 2020 at 10:56 PM

    what is the polling time for implicit wait. Does it recheck after 10 seconds if 10 seconds is the max time mentioned.

    Reply
    • Mukesh Otwani says

      October 15, 2020 at 11:27 PM

      Hi Siddharth,

      It is 0.5 second

      Reply
  3. venkatesh says

    January 1, 2020 at 11:11 PM

    which one will be considered first, when both Implicit and Explicit waits are in picture.
    Some scenarios –
    when Implicit time out is 20 sec and explicit Time out is 30 sec
    What will happen if the element is found out
    1. at 10th sec
    2. at 25th sec
    3. at 31st sec
    4. at 50th sec

    Reply
    • Mukesh Otwani says

      January 2, 2020 at 2:34 PM

      Hi Venkatesh,

      First of all Implicit wait will be applied for all elements and Explicit wait works for specific conditions.
      Now let’s talk about condition if element found within 20 sec then it will continue with execution else it will throw noSuchElementException.

      Thanks
      Mukesh Otwani

      Reply
  4. pooja says

    August 5, 2019 at 10:21 AM

    Hi,

    is this wait time applicable for the entire script once it is mentioned.
    Like will it wait for the element visibility for each and every element in the script?

    Reply
    • Mukesh Otwani says

      August 5, 2019 at 10:35 AM

      Hi Pooja,

      Implicit wait works throughout the script once. But for element visibility, you have to use Explicit wait.

      Reply
  5. dineshkumar says

    June 13, 2019 at 1:10 PM

    what happens if element came after 30 seconds it will throw exceptions

    Reply
    • Mukesh Otwani says

      June 13, 2019 at 9:53 PM

      Hi Dinesh,

      It will throw an exception

      Reply
  6. Ekta says

    May 30, 2019 at 5:29 PM

    Is Implicit wait applicable only for elements which are identified using findElement() method of webdriver instance?

    Reply
    • Mukesh Otwani says

      May 30, 2019 at 7:15 PM

      Hi Ekta,

      Yes, Implicit Wait tell WebDriver to poll DOM while finding an element for given time.

      Reply
  7. Debanjan Bhattacharjee says

    February 16, 2017 at 2:51 PM

    Brilliant explanation on Implicit Wait. Thanks Mukesh !!!

    Reply
    • Mukesh Otwani says

      February 16, 2017 at 3:20 PM

      Thanks Debanjan 🙂 Keep visiting.

      Reply
  8. Raja says

    February 2, 2017 at 7:42 PM

    I want to execute the code slowly to observe each step, how can i use wait for it

    Reply
    • Mukesh Otwani says

      February 2, 2017 at 10:04 PM

      Hi Raja,

      Set toggle breakpoints inside your script and debug it. This way, you can execute step by step.

      Reply
  9. pooja says

    February 2, 2017 at 5:57 PM

    Hi Mukesh,
    Very nice blog i ove it. i have one question.
    Explicity wait will use for all the times like thread.sleep();?

    Reply
    • Mukesh Otwani says

      February 2, 2017 at 10:22 PM

      Hi Pooja,

      As the name of wait i.e. Explicit itself explaining its exclusive and specific usage. And no doubt Explicit waits are better than Thread.sleep().

      Reply
  10. Gaurav Khurana says

    November 22, 2016 at 10:15 AM

    Thanks. It’s helpful and easy to implement and best part was the timeout screenshot that you shared which highlight it weighted for 30 seconds. NewBies generally miss such details. Keep up the good work

    Reply
    • Mukesh Otwani says

      November 23, 2016 at 1:26 PM

      Thanks Gaurav

      Reply
  11. sudhr says

    September 20, 2016 at 6:16 AM

    in tutorial u said that default time is 250 ms.if i mention 30 s. driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); how can this work.what is the total wait…plz explain?

    Reply
    • Mukesh Otwani says

      September 29, 2016 at 2:28 PM

      Hi,

      In above scenario if element not found then max time wait will be 30 seconds and if element comes before 30 seconds it will continue to next steps.

      Reply
  12. sudhr says

    September 20, 2016 at 6:12 AM

    what default timeout for implicit wait..

    Reply
    • Mukesh Otwani says

      September 29, 2016 at 2:31 PM

      Default timeout is ZERO. Default polling time is 250 millisecond if implicit wait given.

      Reply
      • venkatesh says

        December 8, 2019 at 11:59 PM

        what is the polling time for explicit wait?

        Reply
        • Mukesh Otwani says

          December 9, 2019 at 9:51 AM

          Hi Venkatesh,

          Default polling for Explicit Wait in 500 milliseconds…

          Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

Video Player
https://www.youtube.com/watch?v=w_iPCT1ETO4
00:00
00:00
31:21
Use Up/Down Arrow keys to increase or decrease volume.

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?