Time for action – using findElementByClassName() - Selenium

We are going to find an element on the page by using findElementByClassName() method that is on each of the Browser Driver classes. find Element 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:

    WebElement element = ((FindsByClassName)driver). findElementByClassName("storetext");

What just happened?

We have just seen how we can find an element by using the findElementByClassName helper method. After running the test, we saw that it passed.This meant that it found the element. If an element is not found in Selenium, WebDriver will throw a Not Such Element Found exception.

Finding elements on the page by their ClassName

We will now see how we can use it in action. The method's signature looks like:

findElementsByClass(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