You are using WebDriver (got that from your previous Selenium question), and thus the code you are seeing is incorrect. selenium.waitForCondition
is old v1 code. You are using the nice new shiny v2 code.
What you want is specifically the WebDriverWait class that sits in the OpenQA.Selenium.Support
namespace.
var driver = new FirefoxDriver();
var waitableDriver = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
var element = waitableDriver.Until(d => d.FindElement(By.Id("something")));
This would wait until it finds a certain element. However, it allows you to specify any Func<T, TResult>
, thus it gives some great room for flexibility. You can harness the power of lambdas in C#.
What if you wanted to wait for an element to be visible to the user and have a value inside it? What if there is a message when you login that pops up after 5 seconds? All doable.
Also, there are some handy 'expected conditions' that are already made up for you to use, these are common situations that people might need to "wait" for a particular condition to be true, for instance it's common people need to wait until an element is not only rendered in the page but actually visible to the user. There is a ElementIsVisible
expected condition for you to use, so you don't have to make up the logic manually.
This whole concept is known as explicit waits in the Selenium world, and is vital to automating the testing of an AJAX'ified application.