Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Selenium Interview Question 4 – Difference Between @FindBy and findElement() Method in Selenium WebDriver

Posted on 03/16/2025 By admin

We can locate web element/s on a webpage using both FindBy and findElement() or findElements(). Primary purpose of both ways is same but the way it is done, is different.

Below are the differences between FindBy and findElement in Selenium WebDriver:

  1. FindBy is an annotation while findElement and findElements are methods. Remember FindBy is provided by Selenium not by TestNG. I saw some people have commented such differences.
  2. FindBy is used to support PageObject pattern through PageFactory while findElement is normal way of locating a web element.
  3. If we do not initialise page objects using PageFactory, @FindBy will throw NullPointerException which is not the case with findElement() or findElements() methods.
  4. FindBy will look for the element only when it is used while findElement will look for an element as soon as you call it.
  5. FindBy supports lazy initialization while findElement() and findElements does not.
  6. FindBy can be used to locate one or all using a locator but you need to use findElement to locate one element and findElements to locate all elements using a locator.
  7. You need to explicitly keep track of browser driver instance in FindBy annotated page elements i.e. using PageFactory class to initialize page elements while you call findElement() or findElements() directly on browser driver instance.
  8. FindBy helps to handle StaleElementException as it looks for element every time when it is called. If you use findElement() or findElements() method and store the web element, it will not be relocated again until you do it explicitly.
  9. FindBy supports PageObject pattern which helps you in designing neat tests. So Using FindBy is more preferable than findElement() Methods.

I saw some comments saying that FindBy also calls findElement() or findElements() internally. When I saw selenium source code, I found it calls findElement() and findElements() internally but it is not the same as normal findElement() and findElements() which we use.

Normal findElement() and findElements() are declared in WebDriver interface and implemented in RemoteWebDriver class.

While for FindBy, findElement() and findElements() are declared in Element Locator interface.

Class DefaultElementLocator implements ElementLocator. Documentation of this class says : The default element locator, which will lazily locate an element or an element list on a page. This class is

  • designed for use with the {@link org.openqa.selenium.support.PageFactory} and understands the
  • annotations {@link org.openqa.selenium.support.FindBy} and {@link org.openqa.selenium.support.CacheLookup}.

We can use both FindBy and findElement() or findElements() together but it will not impact each other.

Refer more Selenium Interview Questions Here.

If you like my posts, please like, comment and share to reach maximum.

#ThanksForReading

Uncategorized

Post navigation

Previous Post: Postman Tutorial Part 8 – How to Send PUT Request in Postman
Next Post: TestNG Tutorials 68 : Rerun Failed Test Method Using IRetryAnalyzer Interface – Implement Using retryAnalyzer attribute in the @Test annotation

Related Posts

TestNG Tutorials 48: How to Pass Parameters of Different Datatypes in TestNG | Make Selenium Easy Uncategorized
Interview Questions – Make Selenium Easy Uncategorized
August 17, 2018 – Make Selenium Easy Uncategorized
Selenium Archives – Page 3 of 3 – Make Selenium Easy Uncategorized
What will happen if we pass NULL as argument in sendKeys() method Of Selenium WebDriver Uncategorized
image – 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