Skip to main content

findElement and findElements methods are used to find the elements on a webpage. Below are the difference between both:

Point of Distinction findElement findElements
Use A command used to uniquely identify a web element within the web page. Used to identify a list of web elements within the web page.
Returns It returns the first matching element. returns the list of all matching elements. Each Web element is indexed with a number starting from 0 just like an array
NoSuchElementException It throws a NoSuchElementException exception when it fails to find the element. the findElements method returns  an empty list when the element is not available or doesn’t exist on the page. It doesn’t throw NoSuchElementException.
Syntax driver.findElement(By.locatorType("Locators Value")); driver.findElements(By.locatorType("Locator Value"));


package com.pb.seltest.util;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class DiffFindElements 
    WebDriver driver;
    public void befClass()
        System.setProperty("",System.getProperty("user.dir") + "//drivers//chromedriver");
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    public void MyMethod()
        System.out.println("findElement Output");
        WebElement element = driver.findElement(By.xpath("//div[@id='block_top_menu']/ul/li/a"));
        System.out.println("findElements Output");
        List<WebElement> allMenus = driver.findElements(By.xpath("//div[@id='block_top_menu']/ul/li/a"));
        for(int i = 0; i < allMenus.size(); i++)


findElement Output
findElements Output
PASSED: MyMethod

In above example, we are finding menu links for We have used same locators here, but different methods which are findElement and findElements. findElement will only retrieve first link with Name Women and findElements will retrieve all the menu links Women, dresses and t-shirts.

For findElement we are storing result in WebElement because it is returning single result. For findElements we have used List of WebElements because it is returning list of elements.

Video Tutorial


Elix is a premium wordpress theme for portfolio, freelancer, design agencies and a wide range of other design institutions.