Bird
0
0

How would you declare a list of all <button> elements inside a <div> with id "menu" using @FindBy in a Page Object class?

hard📝 Application Q8 of 15
Selenium Java - Page Object Model
How would you declare a list of all <button> elements inside a <div> with id "menu" using @FindBy in a Page Object class?
A@FindBy(xpath = "//div[@id='menu']") private List<WebElement> menuButtons;
B@FindBy(id = "menu") private List<WebElement> menuButtons;
C@FindBy(css = "div#menu button") private List<WebElement> menuButtons;
D@FindBy(tagName = "button") private List<WebElement> menuButtons;
Step-by-Step Solution
Solution:
  1. Step 1: Understand locator requirement

    We want all button elements inside a div with id 'menu'.
  2. Step 2: Analyze options

    A uses CSS selector targeting buttons inside div#menu, which is correct.
  3. Step 3: Why others are incorrect

    B locates div#menu but not buttons inside it; C locates div#menu only; D locates all buttons on page.
  4. Final Answer:

    @FindBy(css = "div#menu button") private List<WebElement> menuButtons; -> Option C
  5. Quick Check:

    Use CSS selector for nested elements [OK]
Quick Trick: Use CSS selector for nested element lists [OK]
Common Mistakes:
MISTAKES
  • Using id locator alone for nested elements
  • Selecting parent element instead of children
  • Using tagName alone selects all buttons globally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes