Implicit and Explicit wait in Selenium




Implicit Wait

The implicit wait will tell to the web driver to wait for certain amount of time before it throws a "No Such Element Exception".
In implicit wait we can select timeout as per below given categories,  SECONDS, MINUTES, MILISECOND, MICROSECONDS, NANOSECONDS, DAYS, HOURS, etc..









Explicit Wait


The explicit wait is used to tell the Web Driver to wait for certain conditions (Expected Conditions) before throwing "ElementNotVisibleException" exception.
By default, it’s time pattern to wait for any element is in second.

In the below example, we are creating reference wait for "WebDriverWait" class and instantiating using "WebDriver"






WebDriverWait wait= null;
@FindBy(xpath=" For list of elements ")
List<WebElement> Elements;
@FindBy(xpath=" Single Element ")
WebElement Element;
private By loaderL=By.xpath(" Single element)]");
public LoginModule(WebDriver driver)
{
PageFactory.initElements(driver, this);
wait= new WebDriverWait(driver,50); // define 50 seconds to web driver for certain condition.
}
wait.until(ExpectedConditions.visibilityOfAllElements(Elements));// this condition is for  visibility of list element
wait.until(ExpectedConditions.visibilityOf(Element));// this condition is for visibility of single element
wait.until(ExpectedConditions.invisibilityOfElementLocated(loaderL));// This condition can be applied for loading icon or progress icon etc..

Below are some conditions which are mostly used in selenium.









No comments:

Post a Comment

Software Testing Automation Guide

  get methods in Selenium Webdriver Below are the list of get methods that can be use with driver. Get()- This com...