Explain implicit and explicit wait?

 


Explain implicit and explicit wait?

    • Implicit Wait: 
      • During Implicit wait if the Web Driver cannot find it immediately because of its availability, the WebDriver will wait for mentioned time and it will not try to find the element again during the specified time period. 
      • Once the specified time is over, it will try to search the element once again the last time before throwing exception. The default setting is zero. 
      • Once we set a time, the Web Driver waits for the period of the WebDriver object instance.
    • Explicit Wait: 

      • There can be instance when a particular element takes more than a minute to load. In that case you definitely not like to set a huge time to Implicit wait, as if you do this your browser will going to wait for the same time for every element.
      • To avoid that situation you can simply put a separate time on the required element only. By following this your browser implicit wait time would be short for every element and it would be large for specific element.
      • Please find the below code snippet for the same.
    =================================================

            WebDriver driver = new FirefoxDriver();
            driver.get("http://somedomain/url_that_delays_loading");
            WebElement myDynamicElement = (new                             WebDriverWait(driver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));

    ================================================

    Post a Comment