How to find Elements by Tag Name using Selenium?

Find Elements by Tag Name

To find all HTML Elements that has a given tag name in a document, using Selenium in Python, call find_elements() method, pass By.TAG_NAME as the first argument, and the tag name (of the HTML Elements we need to find) as the second argument.

find_elements(By.TAG_NAME, "tag_name_value")

find_elements() method returns all the HTML Elements, that match the given tag name, as a list.

If there are no elements by given tag name, find_elements() function returns an empty list.


Consider the below HTML document.


  <p>Paragraph 1</p>
  <div name="xyz">
   <p>Article 1</p>
   <a href="/article-1/">Read More</a>
  <div name="xyz">
   <p>Article 2</p>
   <a href="/article-2/">Read More</a>

In the following program, we will find all the HTML elements whose tag name is 'p', using find_elements() method, and print those elements to the console.

Python Program (Selenium)

from import Service
from selenium import webdriver
from import By

service = Service(executable_path="/usr/local/bin/chromedriver")
#initialize web driver
with webdriver.Chrome(service=service) as driver:
    #navigate to the url
    #find elements by tag name
    elements = driver.find_elements(By.TAG_NAME, 'p')
    for element in elements:


<p>Paragraph 1</p>
<p>Article 1</p>
<p>Article 2</p>


In this tutorial of Python Examples, we learned how to find all the elements by given tag name, present in the webpage, using Selenium.