Implicit, explicit and fluent wait - Selenium (C#)
Difference between Wait and Sleep
- In sleep, the code will just wait for the full amount of time specified, example 10000ms, the code will wait for 10000ms
- In wait, the code will wait for the full amount of time specified or until the condition specified are met whichever comes first.
Example: If you tell the code to wait 10000ms or until it finds a clickable element, if it can find the clickable element in 2000ms, it will proceed to the next step.
WebDriverWait class is under Selenium support UI package
Implicit wait example:
WebDriverWait wait = new WebDriverWait(driverName, TimeSpan.FromSeconds(7));
//this means that the code will wait for 7 seconds
Explicit wait example:
WebDriverWait wait = new WebDriverWait(driverName, TimeSpan.FromSeconds(7));
wait.Until(ExpectedConditions.ElementExists(By.Id("id")));
//this means wait 7 seconds or until the element exists whichever is earlier
To use DotNetSeleniumExtras.WaitHelpers to use ExpectedConditions class
public static void - static means that I can call this method wherever I want without creating an object
Fluent Wait example:
Comments
Post a Comment