Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Selenium Interview Question 10 – Difference Between findElement() and findElements() methods

Posted on 02/08/2025 By admin

As a part of Selenium Interview Questions series, in this post, we will learn differences between findElement() and findElements() methods in Selenium WebDriver.

WebDriver interface provides two methods to locate web element/s. Those are:-

  1. findElement(By by)
  2. findElements(By by)

Difference between findElement() and findElements() are below:-

  1. findElement() is used to find first web element on current page by provided locator mechanism such as id, xpath, css etc whereas findElements() is used to find all web elements on current page by provided locator mechanism such as id, xpath, css etc.
  2. findElement() will return only first web element even provided locator locates more than one web element. findElements() returns all matching web elements. findElement() method internally calls findElements() method itself and return first indexed web element.
  3. Return type of findElement() method is a WebElement whereas return type of findElements() method is a List.
  4. findElement() will throw NoSuchElementException if no matching element is found. findElements() will return an empty list if no matching element is found. This is the reason findElements() is a better way for checking non-presence of web element. Kindly concentrate on this point more. NoSuchElementException is thrown by findElement() not findElements().
  5. findElement() Syntax:- WebElement element = driver.findElement(By.id(“someId”);

    findElement() Syntax:-

    List allElements =driver.findElements(By.xpath(“someXpath”); Where “driver” is a WebDriver reference.

There is another important points which I would like to cover here. It is not difference but common thing between methods. Its impact of Implicit Wait.

Both method findElement() and findElements() are affected by ‘Implicit wait’ times in force at the time of execution. If you do not set any impliict wait, findElement() and findElements() will poll only once and return the result. It means if element is found in first poll, findElement() will return the element otherwise NoSuchElementException . In case of findElements(), it will return a list of matching web elements or an empty list after first poll. Both method will not poll further.

But if you have set Implicit wait, both method will poll repeatedly. findElement() will poll for web element repeatedly till it finds web element or the timeout is reached. If it finds web element before timeout, it returns web element. If it could not find within timeout, it will throw NoSuchElementException exception.

findElements() will poll for web elements and return as soon as there are more than 0 items in the found collection before timeout. If it reaches timeout and finds no element, it will return an empty list.

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappyLearning

Uncategorized

Post navigation

Previous Post: Interview Experience At Morgan Stanley Mumbai For SDET – Sep – 2020
Next Post: Selenium Framework 2: Why Do We Need A Framework In Selenium?

Related Posts

March 31, 2017 – Make Selenium Easy Uncategorized
REST Assured Tutorial 75 – What Is Serialization And Deserialization In Rest Assured? Uncategorized
string Uncategorized
Untitled Diagram (1) – Make Selenium Easy Uncategorized
January 31, 2019 – Make Selenium Easy Uncategorized
March 2019 – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark