Time for action – using findElementsById() - Selenium

We are going to find an element on the page by using the findElementsByld() method that is on each of the Browser Driver classes.

findElement calls will return a WebElement object that we can do 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:

  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 findElementsById helper method. After running the test, we saw that it passed. Unlike its singular version, it will not throw a NoSuchElementException exception if the element is not found. It will return a list that has a size of zero.

Finding an element on the page by its name

The next item that we are going to look at is finding an element by their name. Finding elements by name is just as fast as their ID equivalent. This method is a helper method that sets an argument for a more generic findElement call. We will now see how we can use it in action. The method's signature looks like:

findElementByName(String using);

The using variable takes the ID of the element that you wish to look for. It will return a WebElement object that we can then work with.


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

Selenium Topics