Menu Close
    Start a Project Request quote Reading list Switch to dark mode
    hyperlocal-marketplace-guide

    Implicit and Explicit Waits in Selenium

    What are Waits?

    Waits helps the user to find out the issues while navigating to different web pages. This can be done by refreshing the web pages to reload the web elements. It mights happens that page reload time can be more because of some ajax request due to which webelement takes more time to reflect.

    Need of Waits in Selenium

    Most of the time when we run our Selenium script we get ElementNotVisibleException exception. This happens because Most of the Web Application uses javascript and ajax. Our script execute before getting the response of ajax or javascript request because of which elements are not visible at the time of execution of Script.

    We can overcome this problem by using Selenium Waits. Selenium offers two types of Waits-

    1.Implicit Waits

    2.Explicit Waits

    Implicit Waits

    It will be applicable globally, that means it will work for all the web elements throughout the driver instance.

    Implicit wait will notify the driver to wait for the given amount of time before throwing an exception “No Such Element Exception “. By default it waits for 0 seconds. After setting the time it will wait for that particular time before throwing an exception.

    Syntax of Implicit wait:

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

    Lets take an example to see how Implicit wait works:

    In the above code implicit wait of 30 seconds that means, it will wait for 30 seconds before throwing the exception. Implicit wait takes two parameter, first one is time as integer and second one is measurement of time in form of MINUTE, SECONDS, MILLISECONDS, MICROSECONDS, NANOSECONDS, DAYS, HOURS, etc.

    Explicit Wait

    We use Explicit wait when we have to state driver to wait till some certain condition matches (Expected condition) before throwing an error “ElementNotVisibleException“. It can be Implemented by WebDriverWait class. Unlike Implicit wait, Explicit waits only available for specified Elements.

    After declaring Explicit wait we have to define “Expected Condition”.

    Syntax for Explicit Wait:

    WebDriverWait wait = new WebDriverWait (WebDriverReference,TimeOut);

    When to Use Explicit wait

    Suppose you have to login in some website and after login it takes some time to load data and to reach home page. This page is dynamic so sometime it takes 15 seconds to load the homepage and sometime it takes 30 seconds. So in this case you can use Explicit wait to  wait until a specific page is not present.

    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close