---
title: "How to Find Elements in Selenium: A Beginner’s Guide with Examples"
description: "Learn how to find elements in Selenium using Python. Discover locator types, code examples, and tips for locating web elements on any web page."
url: "https://iproyal.com/blog/selenium-find-element/"
---

- [EN - English](https://iproyal.com/)
   
  [中文 - Chinese](https://iproyal.cn/)

[Book a Demo](https://iproyal.com/request-a-demo/) [Create Account](https://dashboard.iproyal.com/register/) [Create Account](https://dashboard.iproyal.com/register/) [Login](https://dashboard.iproyal.com/login/) [Login](https://dashboard.iproyal.com/login/)

[Book a Demo](https://iproyal.com/request-a-demo/)

[Back to blog](https://iproyal.com/blog/)

# How to Find Elements in Selenium: A Beginner’s Guide with Examples

[Vilius Dumcius](https://iproyal.com/blog/authors/vilius-dumcius/)

[Last updated - December 16, 2025 ‐ 5 min read](https://iproyal.com/blog/authors/vilius-dumcius/)

[Selenium](https://iproyal.com/blog/category/selenium/)

## Key Takeaways

- The *find\_element()* an&#x64;*&#x20;find\_elements()* methods are essential in Selenium projects, with key differences in how they return results.

- Use locator types like IDs, CSS selectors, or names, depending on the HTML structure of the web page.

- For multiple elements, use loops to handle every web element, especially when the elements match your query.

In Selenium, locating web elements is one of the most critical steps. It’s how you tell your script where to click, what to read, or what to type into. You need to be precise and clear to find element targets on a web page.

When you locate an element, Selenium returns a web element object. It can be a button, a link, a text box, or anything else that you can find. Then, you can interact with it. It’s an essential part of all Selenium tasks, and everything depends on it working well.

We’ll walk you through how to find element targets with Selenium WebDriver, the types of locators you can use, and how to handle multiple elements on a page. Additionally, we’ll give you code snippet examples for you to follow along.

## Selenium’s “find\_element” and “find\_elements” Methods

Selenium offers two main tools: *find\_element()* and *find\_elements().* These are used for locating web elements on a web page:

- ***find\_element().&#x20;***&#x47;ets the first matching element it finds.
- ***find\_elements().&#x20;***&#x52;eturns a list of all matching elements.

The syntax looks like:

```python
element = driver.find_element(By.ID, "username")

elements = driver.find_elements(By.CLASS_NAME, "product-title")
```

When you use *find\_element(),* you get a single web element. If no match is found, Selenium throws an error.

When you use *find\_elements(),* it gives back a list of web elements in Selenium. If nothing matches, you get an empty list. It makes *find\_elements()* safer when you expect several elements or aren’t sure if any elements match.

Use *find\_element()* when you only care about the first matching element. Use *find\_elements()* to locate multiple elements, like product titles and buttons.

## Common Locator Types in Selenium WebDriver

A locator tells Selenium how to find element targets on a web page. You point to where it should go, and it follows your instructions. There are many different locator types, but here are some of the most common ones.

### 1. ID Attribute

The ID is the most reliable locator. It should be unique on every web page.

```python
driver.find_element(By.ID, "search-input")
```

### 2. Name Attribute

If the ID attribute is missing, you can try using the name attribute.

```python
 driver.find_element(By.NAME, "email")
```

### 3. Class Name

Use the class name if the element has a class, but be careful. It’s an attribute that’s not always unique, and you may get duplicates.

```python
driver.find_element(By.CLASS_NAME, "submit-button")
```

### 4. Tag Name

It grabs web elements in Selenium by their HTML tag. It’s useful when you want to find multiple elements like all *`<a>`* or *`<button>`* tags.

```python
driver.find_elements(By.TAG_NAME, "a")
```

### 5. CSS Selector

A CSS selector can grab items using class, ID, or other attributes. It’s a flexible method that lets you target complex structures in the HTML.

```python
driver.find_element(By.CSS_SELECTOR, "input[type='text']")
```

### 6. XPath Expression

An XPath expression lets you navigate the tree-like XML document structure of a page. Use XPath when other locators don’t work well.

```python
driver.find_element(By.XPATH, "//div[@class='login-form']//input")
```

## How to Use “find\_element” in Python

Before we begin, you’ll need to download Selenium, which won’t even take long. With Selenium 4.6+, you don’t need to download *chromedriver* manually. Chrome WebDriver will automatically download and configure the correct driver version.

Here is a simple Python script using different locators. It should open a page, grab some elements in Selenium, and print them.

```python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("https://www.saucedemo.com")

wait = WebDriverWait(driver, 10)

username_input = wait.until(EC.presence_of_element_located((By.ID, "user-name")))
print(f"Username placeholder: {username_input.get_attribute('placeholder')}")

password_input = driver.find_element(By.ID, "password")
print(f"Password placeholder: {password_input.get_attribute('placeholder')}")

login_btn = driver.find_element(By.ID, "login-button")
print(f"Login button text: {login_btn.get_attribute('value')}")

logo = driver.find_element(By.CLASS_NAME, "login_logo")
print(f"Logo text: {logo.text}")

driver.quit()
```

Each *find\_element()* grabs a different web element. All you need to do is download Selenium 4.6+, go to the web page, grab what you need, and then do what you need to do with it.

## Finding Multiple Elements With “find\_elements”

If you’re working with web pages that contain lists, for example, product cards, news articles, or buttons, you often need to work with several elements. *find\_elements()* is the function you need to use for that.

It returns a list of web elements in Selenium that match your locator. Then, you can loop through them to read or interact with each one.

Let’s say you want to collect product titles and links from an online store. Each product has a title inside a *`<div>`* with class “product-title” and an anchor tag with the link.

You can locate multiple elements and loop through them like this:

```python
from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome()
driver.get("https://iproyal.com/proxies/")

time.sleep(3)

product_names = driver.find_elements(By.CSS_SELECTOR, "p.tp-headline-s.mb-24.mt-10")
product_links = driver.find_elements(By.CSS_SELECTOR, "a.animated-icon-trigger-hover")

for i in range(len(product_names)):
    print("Product:", product_names[i].text)
    print("Link:", product_links[i].get_attribute("href"))
    print("-" * 30)

driver.quit()
```

It uses both *CLASS\_NAME* and *CSS\_SELECTOR* to find matching elements. Each web element is printed with its text and link.

Here’s an additional quick code snippet for when you want to collect listing buttons on a web page:

```python
buttons = driver.find_elements(By.TAG_NAME, "button")

for button in buttons:
    print("Button Text:", button.text)
```

It grabs all button tags from the HTML and prints their labels. If none of the elements match, the list simply comes back empty instead of crashing.

To ensure you’re always on the right track when finding elements, keep these tips in mind:

- Use *find\_elements()* when you’re sure there are more than 1 element to collect.
- Always loop through the returned list. It may contain 0, 1, or many web elements.
- Combine *get\_attribute()* with each web element to grab details like text, links, or classes.

It helps with locating web elements in bulk during Selenium projects. It’s also key when scraping lists from a web page or a web application, especially when you need to find multiple web elements that follow the same layout.

## Tips for Better Element Location

To get better results when finding web elements, follow these best practices:

- Always start with the ID, if available.
- Avoid over-relying on class names if they’re shared.
- Use CSS selectors for complex layouts.
- Check the HTML structure of the web page using Chrome DevTools.
- Use tools like SelectorsHub, ChroPath, or built-in browser inspection tools.

It should help you find more stable and accurate paths, so your Selenium scripts break less often.

[Create Account](https://dashboard.iproyal.com/)

[Author](https://iproyal.com/blog/authors/vilius-dumcius/)

[Vilius Dumcius](https://iproyal.com/blog/authors/vilius-dumcius/)

[Head of Engineering](https://iproyal.com/blog/authors/vilius-dumcius/)

With six years of programming experience, Vilius specializes in full-stack web development with PHP (Laravel), MySQL, Docker, Vue.js, and Typescript. Managing a skilled team at IPRoyal for years, he excels in overseeing diverse web projects and custom solutions. Vilius plays a critical role in managing proxy-related tasks for the company, serving as the lead programmer involved in every aspect of the business. Outside of his professional duties, Vilius channels his passion for personal and professional growth, balancing his tech expertise with a commitment to continuous improvement.

[Learn More About Vilius Dumcius ](https://iproyal.com/blog/authors/vilius-dumcius/)[Meet all Writers](https://iproyal.com/blog/authors/)

Share on

### In This Article

- [Selenium’s “find\_element” and “find\_elements” Methods](https://iproyal.com/blog/selenium-find-element/#Selenium%E2%80%99s-%E2%80%9Cfind_element%E2%80%9D-and-%E2%80%9Cfind_elements%E2%80%9D-Methods)
- [Common Locator Types in Selenium WebDriver](https://iproyal.com/blog/selenium-find-element/#Common-Locator-Types-in-Selenium-WebDriver)
- [How to Use “find\_element” in Python](https://iproyal.com/blog/selenium-find-element/#How-to-Use-%E2%80%9Cfind_element%E2%80%9D-in-Python)
- [Finding Multiple Elements With “find\_elements”](https://iproyal.com/blog/selenium-find-element/#Finding-Multiple-Elements-With-%E2%80%9Cfind_elements%E2%80%9D)
- [Tips for Better Element Location](https://iproyal.com/blog/selenium-find-element/#Tips-for-Better-Element-Location)

Ready to get started?

[Register now](https://dashboard.iproyal.com/register/)

Data News in Your Inbox

No spam whatsoever, just pure data gathering news, trending topics and useful links. Unsubscribe anytime.

No spam. Unsubscribe anytime.

## Related articles

[View all](https://iproyal.com/blog/category/selenium/)

[Selenium](https://iproyal.com/blog/headless-firefox-python-selenium/)

## [How to Run Headless Firefox with Python Selenium](https://iproyal.com/blog/headless-firefox-python-selenium/)

[Find out how to run Firefox in headless mode with Selenium and when that’s useful to do when scraping or automating browsers.](https://iproyal.com/blog/headless-firefox-python-selenium/)

[August 19, 2024](https://iproyal.com/blog/headless-firefox-python-selenium/)

[5 min read](https://iproyal.com/blog/headless-firefox-python-selenium/)

[Selenium](https://iproyal.com/blog/selenium-stealth-python-tutorial/)

## [Mastering Selenium Stealth for Effective Web Scraping Techniques](https://iproyal.com/blog/selenium-stealth-python-tutorial/)

[Tired of getting blocked while scraping? Discover how to use Selenium Stealth to outsmart bot detection and browse like a real user—undetected and uninterrupted.](https://iproyal.com/blog/selenium-stealth-python-tutorial/)

[June 17, 2025](https://iproyal.com/blog/selenium-stealth-python-tutorial/)

[13 min read](https://iproyal.com/blog/selenium-stealth-python-tutorial/)

[Selenium](https://iproyal.com/blog/selenium-find-element/)

## [How to Find Elements in Selenium: A Beginner’s Guide with Examples](https://iproyal.com/blog/selenium-find-element/)

[Learn how to find elements in Selenium using Python. Discover locator types, code examples, and tips for locating web elements on any web page.](https://iproyal.com/blog/selenium-find-element/)

[December 16, 2025](https://iproyal.com/blog/selenium-find-element/)

[5 min read](https://iproyal.com/blog/selenium-find-element/)
