Bird
0
0

Which of the following is the correct syntax to locate a web element by its ID using @FindBy annotation?

easy📝 Syntax Q12 of 15
Selenium Java - Page Object Model
Which of the following is the correct syntax to locate a web element by its ID using @FindBy annotation?
A@FindBy(id = "submitBtn")
B@FindBy(name = submitBtn)
C@FindBy(xpath = submitBtn)
D@FindBy(css = #submitBtn)
Step-by-Step Solution
Solution:
  1. Step 1: Check correct attribute usage

    The @FindBy annotation requires the attribute name and value as a string. For ID, it is id = "value".
  2. Step 2: Validate each option

    @FindBy(id = "submitBtn") correctly uses id = "submitBtn". @FindBy(name = submitBtn) misses quotes. @FindBy(xpath = submitBtn) uses xpath but without quotes. @FindBy(css = #submitBtn) uses CSS selector but with incorrect syntax (should be css = "#submitBtn").
  3. Final Answer:

    @FindBy(id = "submitBtn") -> Option A
  4. Quick Check:

    Correct syntax uses id with quotes = B [OK]
Quick Trick: Use quotes around locator values in @FindBy [OK]
Common Mistakes:
MISTAKES
  • Omitting quotes around locator values
  • Mixing locator types incorrectly
  • Using invalid syntax for CSS selectors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes