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 findElements()

In this section we are going to look at using the findElements call that is on the WebDriver object. This is how we can normally find elements using Selenium WebDriver.

  1. Open your Java IDE. Intellij or Eclipse are the most used.
  2. We are going to use the command:
    driver.get("http://book.theautomatedtester.co.uk")
    List<WebElement> elements =  driver.findElements(By.linkText("Chapter1"));
    Assert.assertEqual(1, elements.size());
  3. Run your test.

What just happened?

We have used this similar to calls earlier in the chapter. This will find multiple elements on the page and return a list. This will not throw a NoSuchElement exception if it cannot find the element.

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