Bird
0
0

Which of the following is the correct syntax to initialize a WebElement using @FindBy annotation in a Selenium page class?

easy📝 Syntax Q3 of 15
Selenium Java - Page Object Model
Which of the following is the correct syntax to initialize a WebElement using @FindBy annotation in a Selenium page class?
A@FindBy("username") private WebElement usernameField;
B@FindBy(id = "username") private WebElement usernameField;
C@FindBy(id: "username") private WebElement usernameField;
D@FindBy(id == "username") private WebElement usernameField;
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct @FindBy syntax

    The correct syntax uses @FindBy with attribute name and value separated by =, e.g., id = "value".
  2. Step 2: Check each option

    @FindBy(id = "username") private WebElement usernameField; uses correct syntax. The other options have syntax errors like missing attribute name, colon instead of equals, or double equals.
  3. Final Answer:

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

    @FindBy syntax = attribute = "value" [OK]
Quick Trick: Use equals sign in @FindBy attribute assignment [OK]
Common Mistakes:
  • Omitting attribute name in @FindBy
  • Using colon instead of equals
  • Using double equals in annotation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes