Bird
0
0

Identify the error in the following PageFactory initialization code:

medium📝 Debug Q14 of 15
Selenium Java - Page Object Model
Identify the error in the following PageFactory initialization code:
public class HomePage {
  @FindBy(name = "searchBox")
  WebElement searchInput;

  public HomePage(WebDriver driver) {
    initElements(driver, this);
  }
}
AIncorrect locator strategy in @FindBy annotation
BConstructor should not have parameters
CWebElement should be private
DMissing PageFactory class before initElements method call
Step-by-Step Solution
Solution:
  1. Step 1: Check method call syntax

    The method initElements must be called with the class name PageFactory as PageFactory.initElements(...).
  2. Step 2: Verify other code parts

    The locator strategy 'name' is valid, WebElement can be package-private, and constructor can have parameters.
  3. Final Answer:

    Missing PageFactory class before initElements method call -> Option D
  4. Quick Check:

    Always prefix initElements with PageFactory [OK]
Quick Trick: Always call PageFactory.initElements, not just initElements [OK]
Common Mistakes:
  • Calling initElements without PageFactory prefix
  • Thinking locator strategy 'name' is invalid
  • Assuming WebElement must be private
  • Believing constructors cannot have parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes