Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Why It Is Not Possible To Read Locators From External Sources In Page Factory Of Selenium WebDriver

Posted on 04/23/2025 By admin

Hello Folks,

Many automation tester wants to read locators from external sources like database, properties file or excel sheets. Reading locators from external sources and using it in your program is very easy if we don’t use Page Factory. It becomes difficult because of @FindBy annotation.

What is annotation in Java?

Annotations in Java are tags which are used to provide metadata about Class, method, interface, field etc which can be used by Java compiler and JVM. A Java annotation can have elements for which we can pass some values. It is similar to attribute of a web element.

For example:

@FindBy(id=”someID”)
WebElement someElement;

“someID” must be a constant. It must not contain any variable in it.

Understanding the problems in reading locators from external source in Page Factory: 

  1. We use @FindBy annotations with variable of type WebElement at class level. It is not possible to call any method at class level i.e. outside any method in java. Also you can not create any method which can return you webelemet declaration with @FindBy annotation.

2. Suppose somehow you find any solution of above problem, there is another problem .Suppose you arrange locators with locator strategy in external source as “LocatorStrategy:LocatorValue”. When you split using code, you will store “LocatorStrategy” and “LocatorValue” in two different variables and you will write as below:

As soon as you write as above, Java compiler will give you error because it is expecting some locator strategy like id, name, xpath etc rather than any variable.

So, you need to face above problems if you want to read locators from external sources. You can do max parameterisation as below:

So, as of my knowledge, if you use page factory, you can not read locators from external sources.  But if you use plain page object model, you can read locators from external sources easily.

That’s it guys. Hope you would have clear concepts now. If you have any doubt, feel free to comment below. If you like my posts, please like, comment, share and subscribe. #ThanksForReading

#HappySelenium

Uncategorized

Post navigation

Previous Post: Postman Tutorial Part 43 – Create Parameterized Request by Reading Data From JSON in Postman
Next Post: Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Related Posts

SelectCLass – Make Selenium Easy Uncategorized
March 4, 2019 – Make Selenium Easy Uncategorized
Way2 – Make Selenium Easy Uncategorized
Amod Mahajan, Author at Make Selenium Easy – Page 4 of 49 Uncategorized
May 12, 2018 – Make Selenium Easy Uncategorized
Frequently Asked Java Programs: 33 – Insert a String into Another String at given index 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