Synchronizing a test with custom-expected conditions
With the explicit wait mechanism, we can also build custom-expected conditions along with common conditions using the ExpectedConditions
class. This comes in handy when a wait cannot be handled with a common condition supported by the ExpectedConditions
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 ExpectedCondition
class as follows:
@Test public void testExplicitWait() { WebDriver driver = new FirefoxDriver(); // Launch the sample Ajax application driver.get("http://cookbook.seleniumacademy.com/AjaxDemo.html"); try { driver.findElement(By.linkText("Page 4")).click(); ...
Get Selenium Testing Tools Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.