Time for action – using findElementsByLinkText() - Selenium

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.

  3. Run the test from the IDE. It will look like the following screenshot:

What just happened?

We have just seen how we can find an element by using the findElementsByLinkText helper method. One thing to note is that the search for the text is case sensitive. If an element is not found in Selenium, WebDriver will return an empty list.

Pop quiz - finding elements using helper methods

  1. What is the best call for finding multiple elements using XPath?

    1. findElementByXpath

    2. findElementsByXPath

    3. findElementByCssSelector

  2. What is the best call to an element using CSS selectors to find an element just on the class name?

    1. findElementById

    2. findElementsByCssSelector

    3. findElementByClassName

  3. Will a findElements type call throw a NoSuchElementException when it can't find the element?

Have a go hero - using findElement Helper methods

Try creating an example where you need to find an element by CSS selector. This is used by findElementByCssSelector and findElementsByCssSelector. Have a try!


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Selenium Topics