Synchronizing a test with custom-expected conditions
The Selenium WebDriver also provides a way to build custom-expected conditions along with common conditions using the ExpectedCondition
class. This comes in handy when a wait can be handled with a common condition supported by the ExpectedCondition
class.
In this recipe, we will explore how to create a custom condition.
How to do it...
We will create a test that will create a wait until an element appears on the page using the custom ExpectedCondition
class as follows:
@Test public void testExplicitWait() { //Go to Sample Application WebDriver driver = new FirefoxDriver(); driver.get("http://dl.dropbox.com/u/55228056/AjaxDemo.html"); try { //Get the link for Page 4 and click on it, this will call AJAX code //for loading the contents for Page 4 WebElement page4button = driver.findElement(By.linkText("Page 4")); page4button.click(); //Create Wait using WebDriverWait. ...