3

I understand both waits and use of it. But one thing that I could not figure out is : If I put implicit wait for 5 seconds at top and then use explicit wait for an element. Then how selenium will behave. Tried but could not get satisfactory answer on net.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Nipun Kumar
  • 143
  • 1
  • 6
  • 16
  • For the element for which explicit wait is defined will wait for the certain condition to happen, if that condition is not satisfied within explict time, driver will throw element not found exception. – ANIL KUMAR Apr 15 '20 at 10:26

1 Answers1

4

First understand the concepts of Explicit and Implicit wait

Implicit Wait: An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance. For Example:

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));

Explicit Wait:

  1. An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code.
  2. There are some cases where the explicit wait is functionally equivalent to implicit wait, means a) Where waiting time is not predefined like below (please note they were distinct by method category they belong explicit or implicit)

    WebDriverWait wait = new WebDriverWait(driver, 10);
    

    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));

    b) Cases where the webdriver has a time to wait 10 seconds but at the 5 second the element was found then the webdriver will proceed.

Answer of your Question: 1) Suppose you have defined 10 seconds then driver waits for 10 maximum but at minimum it can wait for 0.001 seconds means in cases of implicit wait we have to give maximum limit for wait while minimum limit depends on the finding the element or getting the condition done.

2) While in explicit wait except some case webdriver has to wait for maximum limit.


So, as a answer your webdriver first will follow the implicit wait and then follow the explicit wait since browser behavior will be sequential like other programing languages due single thread usage.


Reference :

Selenium Explicit and Implicit wait