Synchronization issues with Mixing Implicit Wait And Explicit Wait in selenium webdriver.
Like our facebook page www.facebook.com/ankprotraining
ImplicitWait
ExplicitWait
Issues with mixing ImplicitWait and ExplicitWait
Implicit Wait in selenium webdriver
On implementing implicit wait, if WebDriver cannot find an element in the Document Object Model(DOM), it will wait for a defined amount of time for the element to appear in the DOM
Driver will look for the element by polling every 500 milli second
Driver will wait specified amount time or element is available in the DOM
If the element is not available even after the specified time, driver will throw ElementNotFound exception
Usage: driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
Explicit Wait in selenium webdriver :
An explicit wait can only be implemented in cases where synchronization is needed for an element and the rest of the script is working fine.
Explicit wait can be used to verify the page title, page url or to find the element.
The Selenium WebDriver provides WebDriverWait and ExpectedCondition classes for implementing an explicit wait.
The WebDriverWait object will call the ExpectedConditions class method for every 500 milliseconds until it returns successfully or specified time is over.
Usage: WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20)); wait.Until(ExpectedConditions.ElementExists(By.ClassName("ContactUs")));
Possible Interview Questions on implicit wait and explicit wait in selenium webdriver :
What is ImplicitWait and ExplicitWait?
What is the difference between Implicit and ExplicitWait?
Which kind of issues we will face if we mix ImplicitWait and ExplicitWait ?
Code :
[TestMethod]
public void ImplicitAndExplicitMix()
{
IWebDriver driver = new ChromeDriver();
driver.Url = "[ Ссылка ]";
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
Stopwatch watch=null;
try
{
watch = Stopwatch.StartNew();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
wait.Until(ExpectedConditions.ElementExists(By.Id("Dummy")));
driver.FindElement(By.Id("something")).Click();
}
catch(Exception e)
{
watch.Stop();
Console.WriteLine(e);
Console.WriteLine(watch.ElapsedMilliseconds + " Milli seconds");
}
driver.Quit();
}
![](https://i.ytimg.com/vi/m07qrQzP6VY/mqdefault.jpg)