Tuesday, 29 December 2015

Difference between 'implicit wait' and 'explicit wait'? in selenium




In Implicit Wait , we define a code to wait for a certain amount of time when trying to find an element or elements. If the Web Driver cannot find it immediately because of its availability, the WebDriver will wait. The default setting is zero. Once we set a time, the Web Driver waits for the period of the WebDriver object instance.
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

In Explicit Wait, we write a code to define a wait statement for certain condition to be satisfied until the wait reaches its timeout period. If WebDriver can find the element before the defined timeout value, the code execution will continue to next line of code. Therefore, it is important to setup a reasonable timeout seconds according to the system response.
WebDriverWait wait = new WebDriverWait(driver, 30);  
      wait.until(ExpectedConditions.presenceOfElementLocated(by)); 

No comments:

Post a Comment