What if Implicit and Explicit wait are both used in the Framework

I understand both the expectations and its use. But one thing I couldn't figure out is if I put an implicit wait for 5 seconds and then use an explicit wait for an element. Then how will selenium behave. Tried it but couldn't get a satisfactory answer online.

+3


source to share


2 answers


Understand the concepts of explicit and implicit waiting first

Implicit wait: Implicit wait is to tell WebDriver to poll the DOM for a specified amount of time when trying to find an element or elements if they are not immediately available. The default is 0. Once set, an implicit wait is set for the lifetime of an instance of a WebDriver object. 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:

  • Explicit wait is code that you define to wait for a certain condition to occur before continuing with the code.
  • There are cases where an explicit wait is functionally equivalent to an implicit wait, means a) If the wait time is not predefined as below (note that they differ by method category, they belong explicitly or implicitly)

    WebDriverWait wait = new WebDriverWait(driver, 10);
    
          

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

    b) Cases where the webdriver has a timeout of 10 seconds, but within 5 seconds the item was found, after which the webdriver will continue.

The answer to your question is: 1) Suppose you define 10 seconds, then the driver waits for 10 maximum values, but at least he can wait 0.001 seconds in case of implicit wait, we have to give the maximum limit for waiting, while the minimum limit depends from finding an item or getting a condition did.



2) While in explicit pending, except in some case, the webdriver must wait for the maximum limit.


So, as a response, your webdriver will follow an implicit wait first and then follow an explicit wait, since the browser behavior will be consistent like other programming languages โ€‹โ€‹due to the use of a single thread.


Link:

Selenium Explicit and Implicit wait

+4


source


if ur uses an implicit wait of 5 seconds at the top of ur explicit wait and ur page does not load completely at the given time, then you will get a "timeout exception" by waiting implicitly. While in another case, if ur page loads after 5 seconds then ur element is loaded automatically, I suggest that it is better to try explicitly on top of ur implicit wait.



-1


source







All Articles