Bird
0
0

Which of the following is the correct way to declare a WebElement using PageFactory in Selenium Java?

easy📝 Conceptual Q2 of 15
Selenium Java - Page Object Model
Which of the following is the correct way to declare a WebElement using PageFactory in Selenium Java?
Aprivate WebElement usernameField = new WebElement();
BWebElement usernameField = driver.findElement(By.id("username"));
C@FindBy(id = "username") private WebElement usernameField;
D@FindElement(name = "username") WebElement usernameField;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct annotation for PageFactory

    PageFactory uses @FindBy annotation to locate elements.
  2. Step 2: Check syntax correctness

    @FindBy(id = "username") private WebElement usernameField; is the correct syntax.
  3. Final Answer:

    @FindBy(id = "username") private WebElement usernameField; -> Option C
  4. Quick Check:

    @FindBy annotation = Correct WebElement declaration [OK]
Quick Trick: Use @FindBy to declare WebElements for PageFactory [OK]
Common Mistakes:
MISTAKES
  • Using @FindElement instead of @FindBy
  • Instantiating WebElement directly
  • Mixing driver.findElement with PageFactory declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes