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

We are going to find an element on the page by using the findElementsByLinkText() method that is on each of the Browser Driver classes. findElements calls will return a list of WebElement objects 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.
    driver.get("http://book.theautomatedtester.co.uk")
    List<WebElement> elements = ((FindsByLinkText)driver).findElementsByLinkText("Chapter1");
    Assert.equals(1, elements.size());
  3. Run the test from the IDE. It will look like the following screenshot:
    Time for action – using findElementsByLinkText()

What just ...

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