Bird
0
0

Which of the following is the correct way to use @FindBy to locate a button element by its CSS class submit-btn?

easy📝 Syntax Q3 of 15
Selenium Java - Page Object Model
Which of the following is the correct way to use @FindBy to locate a button element by its CSS class submit-btn?
AAll of the above
B@FindBy(className = "submit-btn") private WebElement submitButton;
C@FindBy(xpath = "//button[@class='submit-btn']") private WebElement submitButton;
D@FindBy(css = ".submit-btn") private WebElement submitButton;
Step-by-Step Solution
Solution:
  1. Step 1: Understand locator strategies

    CSS selector, className, and XPath can all locate elements by class.
  2. Step 2: Analyze each option

    A uses CSS selector for class, B uses className, C uses XPath targeting class attribute.
  3. Step 3: Validity

    All three syntaxes are valid for locating a button with class 'submit-btn'.
  4. Final Answer:

    All of the above -> Option A
  5. Quick Check:

    Multiple locators can target class [OK]
Quick Trick: CSS, className, XPath can locate by class [OK]
Common Mistakes:
  • Assuming only one locator works for class
  • Confusing className with CSS selector syntax
  • Using incorrect XPath syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes