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

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

Follow these steps to see how it works:

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

What just happened?

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