O'Reilly logo

Selenium 2 Testing Tools Beginner's Guide by David Burns

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – using explicit waits with Selenium WebDriver

In this section we will have a look at using explicit waits. This is useful for making sure that the right type of exception is thrown:

  1. Open your Java IDE.
  2. We are going to use the following code. WebDriverWait is found in the Support package within the Selenium WebDriver Jar.
    WebElement element = (new WebDriverWait(driver, 10))
      .until(new ExpectedCondition<WebElement>(){
        @Override
        public WebElement apply(WebDriver d) {
          return d.findElement(By.xpath("//div[@id='ajaxdiv']")
    }});
  3. Run your tests:
    Time for action – using explicit waits with Selenium WebDriver

What just happened?

We have just seen how we can use an explicit wait with our code. We told the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required