Skip to content
Abode QA
Abode QA

A Hub For Testing Minds…

  • Home
  • Video Tutorial
    • Selenium WebDriver
    • Spock Framework
    • Katalon Studio
    • Git Tutorial
    • SQL Tutorial
    • Geb & Spock
    • Groovy
  • Manual Testing
  • Selenium-WebDriver
  • Quiz
    • Selenium WebDriver Quiz
    • Software Testing Quiz | Software Testing Interview Preparation Question
  • Java Tutorial
  • Katalon
  • Fitnesse
  • Daily Bytes!!
Abode QA

A Hub For Testing Minds…

Implicit Wait in Selenium WebDriver

Dwarika Dhish Mishra, March 12, 2013March 2, 2016

Implicit wait in Selenium WebDriver introduction:

Implicit wait in WebDriver has solved many issues that occurs due to intensive use of Ajax in any webpage. Ajax intends loading time of each element on webpage to vary.Due to different loading time, it become cumbersome to find all element on web page as soon as web page opens and this causes your script to fail.
Implicit wait specifies the amount of time the driver should wait when searching for an element if it is not immediately present. So to search any element on webpage driver will poll the page till the time it does not found element or time out expires and then it throws exception like “NoSuchElementException”.




Watch video to know more about facts of Implicit Wait

Trending
How AI is Revolutionizing Software Testing and Enhancing Quality

Few important points about Implicit wait:
1-
Implicit wait is called global wait because once it is declared it stay with WebDriver instance for its life time.
2- It comes in to action, as soon as it sees any driver.findElement/driver.findElements statement in code. it means it will wait for all the statements made to find WebElement on webpage.
3- Default wait is “0” that can be custom as per our need depending upon network latency.
4- Implicit wait should be avoided with slow locator like xpath due to its adverse impact on script run time.
Before moving ahead why not we see code snippet taken from WebDriver api which have all the code of TimeOut interface

  
  interface Timeouts {

    
    / *
     * @param time The amount of time to wait.
     * @param unit The unit of measure for {@code time}.
     * @return A self reference.
     */
    Timeouts implicitlyWait(long time, TimeUnit unit);

   
     *
     * @param time The timeout value.
     * @param unit The unit of time.
     * @return A self reference.
     * @see JavascriptExecutor#executeAsyncScript(String, Object...)
     */
    Timeouts setScriptTimeout(long time, TimeUnit unit);

    /**
     * 
     * @param time The timeout value.
     * @param unit The unit of time.
     * @return A Timeouts interface.
     */
    Timeouts pageLoadTimeout(long time, TimeUnit unit);
  }

Source :  WebDriver Code

As we can see in above code that implicitlyWait take two parameters, First parameter takes the time for which driver instance have to wait and second instance is an enum TimeUnit which have constants like Seconds, Minutes, Hours, Days,milliSeconds, micoSeconds and nanoSeconds.
So if someone has taken 5 as time to wait and TimeUnit.SECONDS then it means driver instance will wait for next 5 seconds before throwing exceptions if element is not found on webpage.
code snippet used for implicitlyWait

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

above line of code should be used just after driver instance is initialise.
So lets take one example of implicit wait.




Scenario:
1- Open bing website
2- Enter Selenium Tutorials string in search text field
3- Once string will be entered in textfield, some ajax drop down will appear and in this first choice should be selected.

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 IMplicitWaitInWebDriver {
@Test
public void test()
{
	WebDriver driver = new FirefoxDriver();
	
	
	driver.get("http://bing.com");
	driver.findElement(By.name("q")).sendKeys("Selenium Tutorials");
	// Implicit wait :  is global wait for webelement
	driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	
	driver.findElement(By.xpath("//*[@id='sa_2']/div/div")).click();
}

}

Description of above code:
above code will open one firefox instance and will open bing.com and after opening bing.com it will enter Selenium Tutorials string in search box but as soon as we will enter string ajax dropdown will not appear on screen and for this we need to wait for 2-3 seconds so for safer side, have used 5 second in code and after 5 second elapsed code will perform the action of selecting the first dropdown option.

Popular Posts

  • How AI is Revolutionizing Software Testing and Enhancing Quality
  • Delete, Truncate and Drop Statement In SQL with Example
  • How to Run Selenium Scripts In Tor Browser?
  • What are Web Services, Types And Its Advantages?

Share this:

  • Tweet
  • More
  • Pocket
  • Email
  • Reddit
  • Share on Tumblr
  • Print
  • WhatsApp

Related

Selenium WebDriver Tutorial Implicit waitImplicit wait in WebDriverSelenium WebDriver implicit wait

Post navigation

Previous post
Next post

Leave a ReplyCancel reply

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

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,582 other subscribers
  • How to Connect Selenium To Existing Chrome Browser?
  • Top Mozilla Firefox Plugins For Better Productivity With Key Features!!
  • How To Run Selenium Tests In Brave Browser Using ChromeDriver?
  • Top Chrome Extensions For Better Productivity !!
  • Top Best Software Testing Trends to watch out in 2021
  • Top-Notch Mozilla Firefox Add-ons to Install
  • 10 Best FREE YouTube Video Downloader Apps For Year 2021.
  • WebDriverManager: New Way to handle driver binaries in Selenium
  • Requirement of Testing environment
  • How To Create S3 Bucket Command? | AWS CLI Commands

Top Posts & Pages

  • Reviews,Walkthrough And Inspection In Software Testing
    Reviews,Walkthrough And Inspection In Software Testing
  • How to Connect Selenium To Existing Chrome Browser?
    How to Connect Selenium To Existing Chrome Browser?
  • How to use Contains() and starts-with() function in Xpath
    How to use Contains() and starts-with() function in Xpath
  • 5 Commonly Asked Java String Question in Selenium Interview
    5 Commonly Asked Java String Question in Selenium Interview
  • Installation Testing and Test Cases For Good Installation Testing
    Installation Testing and Test Cases For Good Installation Testing
  • Test Cases To Test Software Updates Before Its Release
    Test Cases To Test Software Updates Before Its Release
  • Arrays in Java and its implementation in WebDriver
    Arrays in Java and its implementation in WebDriver
  • SSH To Ubuntu Installed On VirtualBox | Putty To Ubuntu
    SSH To Ubuntu Installed On VirtualBox | Putty To Ubuntu
  • assertTrue(message,condition) in Selenium WebDriver and it's implementation
    assertTrue(message,condition) in Selenium WebDriver and it's implementation
  • Upload and Download file from FTP Server using Java FTP Client
    Upload and Download file from FTP Server using Java FTP Client
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
©2023 Abode QA | WordPress Theme by SuperbThemes