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

We are going to find an element on the page by using the findElementsByXPath() method that is on each of the Browser Driver classes. findElement calls will return a WebElement object that we can perform actions on.

Follow these steps to see it work:

  1. Open your Java IDE. Intellij or Eclipse are the most used.
  2. We are going to use the command:
    List<WebElement> elements = ((FindsByXPath)driver).findElementsByXpath("//input");
    Assert.equals(5, elements.size());
  3. Run the test from the IDE. It will look like the following screenshot:
    Time for action – using findElementsByXpath()

What just happened?

We have just seen how we can find an element by using 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