October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Locate Elements by Tag Name in Selenium

Use Selenium’s tag-name locator to find one element or collect all elements of a given HTML type, and learn how to narrow broad matches.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Selenium’s tag-name locator with the HTML tag, without angle brackets. In Python, for example: driver.find_element(By.TAG_NAME, "a") finds one anchor element. Use the plural method, find_elements, when you need all matching elements.

Find an element by tag name

Pass the tag as a string to the tag-name locator. The tag must be the name used in the page’s HTML, such as a, input, button, or tr—not a value in angle brackets.

As an Amazon Associate I earn from qualifying purchases.

Python

from selenium.webdriver.common.by import By

element = driver.find_element(By.TAG_NAME, "a")

The current Selenium Python API reference also demonstrates locating a div with By.TAG_NAME.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Java

WebElement element = driver.findElement(By.tagName("a"));

C#

driver.FindElement(By.TagName("a"));

Selenium’s locator documentation shows these language-specific forms. A tag-name locator matches the element type; it does not identify an element by its class, ID, text, or other attribute.

Find all elements with a tag

Use the plural finder to collect all matching elements. For example, in Python:

inputs = driver.find_elements(By.TAG_NAME, "input")

for input_element in inputs:
    print(input_element.get_attribute("type"))

The singular finder returns one matching element; the plural finder returns a collection. If no elements match, the plural finder returns an empty list rather than reporting a missing-element error. See Selenium’s documentation on finding elements.

Choose a locator that identifies the right element

Tag-name lookup is useful when the element type itself is what you need, or when you intentionally want a collection such as all links or inputs. It can be too broad for selecting one particular control: pages commonly contain many elements with the same tag. Selenium cautions that tag name can be a dangerous locator strategy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • One specific element: Prefer a unique, consistently predictable ID when the page provides one. This is Selenium’s general locator guidance.
  • A known section: Find the parent first, then search inside it to narrow the matches.
  • Every element of a type: Use the plural finder and inspect the returned elements or apply further criteria.

For example, to find an input within a particular form in Python:

form = driver.find_element(By.ID, "contact-form")
email_input = form.find_element(By.TAG_NAME, "input")

Replace contact-form with the actual unique ID in your page. Selenium documents searching within a parent element as a way to scope a lookup: element finders and scoped searches.

Common problems and fixes

  • No element found with the singular finder: Check that the tag exists in the current page and that you used its name without angle brackets. If the element is not present yet, wait for the page or relevant content to load before locating it.
  • The plural finder returns an empty list: Selenium found no elements matching that tag at lookup time. Confirm the current page and tag, and account for content that loads dynamically.
  • You get the wrong element: A tag-only locator may match several nodes. Use a unique ID or locate a known parent and search within it.
  • A collection contains more elements than expected: That is normal when the tag is shared across the page. Inspect attributes or narrow the search context instead of assuming the first match is the intended one.

Or skip the browser setup

If your goal is a visual snapshot rather than interacting with page elements, ScreenshotNeo can return an image or PDF with one GET request. Its API accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and responses report the page verdict and billing status. Its MCP server provides screenshot and PDF tools for AI agents.

Example cURL request (replace YOUR_API_KEY with your key):

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Does Selenium’s tag-name locator include angle brackets?

No. Pass the tag string, such as `”button”`, not `”

Your address stays with us — privacy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.