Bird
0
0

What is wrong with this @FindBy usage?

medium📝 Debug Q7 of 15
Selenium Java - Page Object Model
What is wrong with this @FindBy usage?
@FindBy(name = "searchBox", id = "search")
private WebElement searchInput;
AThe syntax is correct; it will find element by name or id.
BThe field must be static to use multiple locators.
CThe WebElement must be initialized manually.
DMultiple locator attributes cannot be used together in @FindBy.
Step-by-Step Solution
Solution:
  1. Step 1: Understand @FindBy attribute rules

    @FindBy supports only one locator attribute at a time (like id or name), not multiple simultaneously.
  2. Step 2: Analyze given code

    Using both name and id attributes together in @FindBy is invalid and causes a compile-time or runtime error.
  3. Final Answer:

    Multiple locator attributes cannot be used together in @FindBy. -> Option D
  4. Quick Check:

    @FindBy allows only one locator attribute per annotation [OK]
Quick Trick: Use only one locator attribute per @FindBy annotation [OK]
Common Mistakes:
  • Trying to combine multiple locators in one @FindBy
  • Assuming multiple locators work as OR condition
  • Forgetting to use @FindBys or @FindAll for multiple locators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes