title: Selenium - Is it okay to mix implicit wait and explicit wait like this?
body: <p>Here is a <a href="https://www.udemy.com/course/selenium-webdriver-advanced-framework/" rel="nofollow noreferrer">udemy course</a> (from "Lets Kode It") to develop a web automation framework with selenium and Java. <strong>But, this is not a java question.</strong> You only need to know selenium in any of these languages - javascript, python, ruby, c# &amp; java.</p>
  
  <p>The instructor has developed a CustomDriver class which has the method/function given below. The method waits for an element to be clickable, without having to write <code>WebDriverWait</code> statements everywhere in our code. It first sets the implicit wait to zero, does an explicit wait and then sets the implicit wait to the original value which was being used in the framework.</p>
  
  <p>This approach seems okay to me, but I am not sure about it. Could mixing implicit and explicit waits like this cause any problems?</p>
  
  <p><strong>UPDATE</strong> (March 24, 2020) - I already know that mixing implicit and explicit waits is considered a bad practice because it can lead to unpredictable wait times. I am not asking about the unpredictable wait times because there are plenty of questions and articles on that already. </p>
  
  <p>Instead, I am asking that if the implicit wait is set to zero every time before doing an explicit wait, then is that okay? Will that still cause the problems of unpredictable waits? Will it cause other problems ?</p>
  
  <pre><code>/*
   Click element when element is clickable
   @param locator - locator strategy, id=&gt;example, name=&gt;example, css=&gt;#example,
                         tag=&gt;example, xpath=&gt;//example, link=&gt;example
   @param timeout - Duration to try before timeout
   */
  public void clickWhenReady(By locator, int timeout) {
      try {
          driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
          WebElement element = null;
          System.out.println("Waiting for max:: " + timeout + " seconds for element to be clickable");
  
          WebDriverWait wait = new WebDriverWait(driver, 15);
          element = wait.until(
                  ExpectedConditions.elementToBeClickable(locator));
          element.click();
          System.out.println("Element clicked on the web page");
          driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
      } catch (Exception e) {
          System.out.println("Element not appeared on the web page");
          driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
      }
  }
  </code></pre>