Bird
0
0

Consider this code:

medium📝 Predict Output Q5 of 15
Selenium Java - Page Object Model
Consider this code:
@FindBy(xpath = "//input[@name='email']")
private WebElement emailInput;

public String getEmailPlaceholder() {
    return emailInput.getAttribute("placeholder");
}

If the input element has placeholder="Enter your email", what will getEmailPlaceholder() return?
A"Enter your email"
Bnull
CAn empty string ""
DThrows NoSuchElementException
Step-by-Step Solution
Solution:
  1. Step 1: Understand getAttribute behavior

    The method getAttribute("placeholder") returns the value of the placeholder attribute if present.
  2. Step 2: Given placeholder attribute value

    The input element has placeholder="Enter your email", so the method returns this exact string.
  3. Final Answer:

    "Enter your email" -> Option A
  4. Quick Check:

    getAttribute returns attribute value string [OK]
Quick Trick: getAttribute returns exact attribute value string [OK]
Common Mistakes:
MISTAKES
  • Expecting null if attribute exists
  • Confusing getText() with getAttribute()
  • Assuming exception if element exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes