Last active
September 12, 2018 15:55
-
-
Save nadvolod/b3a4f1c44f229a18037d48290df4994e to your computer and use it in GitHub Desktop.
This is how you do an explicit wait in Selenium WebDriver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//EXAMPLE 1 - This is the most convenient method provided to us by the Webdriver API | |
//ExpectedConditions class provides us many different options for locating an element | |
var wait = new WebDriverWait(_driver,TimeSpan.FromSeconds(10)); | |
wait.Until(ExpectedConditions.ElementIsVisible(By.Id("elementId"))); | |
//EXAMPLE 2 - This is a wait that dynamically checks for the presence of an element for a maximum amount of time, a bit burdensome | |
//because we had to write it | |
IWebDriver driver = new FirefoxDriver(); | |
driver.Url = "http://somedomain/url_that_delays_loading"; | |
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); | |
IWebElement myDynamicElement = wait.Until<IWebElement>((d) => | |
{ | |
return d.FindElement(By.Id("someDynamicElement")); | |
}); | |
//EXAMPLE 2 - This is the worst kind of wait and should almost never be used | |
Thread.Sleep(10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My code is in C#, yours is in Java. Your conventions are probably a bit different in Java. Check Explicit Waits in Java @MSithara