Selenium WebDriver's By class provides a tagName() method to find elements by their HTML tag name. This is similar to the getElementsByTagName() DOM method in JavaScript.
This is used when you want to locate elements using their tag name, for example, locating all <tr> tags in a table.
In this recipe, we will briefly see how to use the tagName() locator method.
How to do it...
Let's assume you have a single button element on a page. You can locate this button by using its tag in the following way:
The tagName() locator method queries the DOM and returns a list of matching elements for the specified tag name. This method may not be reliable while locating individual elements and the page might have multiple instances of these elements.
See also
The Finding elements using findElements method recipe