How can I use TagName locator in Selenium automation scripts?

Can anyone please tell me how can I use TagName locator in Selenium automation scripts.

1 Like

When you don’t have attribute values like ID, class, or name but need to locate an element, you may have to depend on Selenium’s tagName locator. For example, if you want to retrieve data from a table, you can do so by using the <td > or <tr > tags.

In Selenium, the command to locate an element via tagName is:

driver.findElement(By.tagName("input"));