Bird
0
0

Examine the following code snippet:

medium📝 Debug Q6 of 15
Selenium Java - Page Object Model
Examine the following code snippet:
@FindBy(id = "password")
private WebElement passwordField;

public void enterPassword(String pwd) {
    passwordField.sendKeys(pwd);
}

Assuming the element is present on the page, what is the likely issue here?
AThe locator id "password" is invalid syntax
BThe WebElement is not initialized because PageFactory.initElements() was not called
CsendKeys() cannot be used on WebElement fields
DThe method enterPassword should return a boolean
Step-by-Step Solution
Solution:
  1. Step 1: Check WebElement initialization

    Using @FindBy requires calling PageFactory.initElements() to initialize elements.
  2. Step 2: Analyze code snippet

    Code snippet does not show initialization; without it, passwordField remains null.
  3. Step 3: Other options

    Locator syntax is valid, sendKeys() is correct, and return type is not mandatory.
  4. Final Answer:

    The WebElement is not initialized because PageFactory.initElements() was not called -> Option B
  5. Quick Check:

    Always initialize elements with PageFactory [OK]
Quick Trick: Missing PageFactory.initElements() causes null WebElement [OK]
Common Mistakes:
  • Forgetting to initialize PageFactory
  • Assuming locator syntax error without checking
  • Misunderstanding sendKeys usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes