Bird
0
0

What is wrong with this PageFactory initialization?

medium📝 Debug Q7 of 15
Selenium Java - Page Object Model
What is wrong with this PageFactory initialization?
public class DashboardPage {
  @FindBy(css = ".profile-link")
  private WebElement profileLink;

  public DashboardPage(WebDriver driver) {
    PageFactory.initElements(driver, DashboardPage.class);
  }
}
AinitElements should be called outside constructor.
B@FindBy annotation is incorrect for CSS selector.
CSecond argument should be 'this', not the class object.
DWebElement must be public to initialize.
Step-by-Step Solution
Solution:
  1. Step 1: Understand initElements second parameter

    The second parameter must be the current page object instance, 'this', not the class object.
  2. Step 2: Verify other parts

    @FindBy with css is correct, WebElement can be private, initElements is called correctly inside constructor.
  3. Final Answer:

    Second argument should be 'this', not the class object. -> Option C
  4. Quick Check:

    Use 'this' as second argument in initElements [OK]
Quick Trick: Always pass 'this' as second argument to initElements [OK]
Common Mistakes:
  • Passing class instead of instance
  • Misusing @FindBy syntax
  • Thinking WebElement must be public

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes