Bird
0
0

Consider the following Selenium Java code snippet:

medium📝 Predict Output Q13 of 15
Selenium Java - JavaScriptExecutor
Consider the following Selenium Java code snippet:
WebElement input = driver.findElement(By.id("username"));
String value = input.getAttribute("value");
System.out.println(value);

If the input field has value="testUser", what will be printed?
AtestUser
Bnull
Cvalue
Dusername
Step-by-Step Solution
Solution:
  1. Step 1: Identify the attribute being fetched

    The code calls getAttribute("value") on the input element, which returns the current value attribute.
  2. Step 2: Match attribute value with output

    The input field has value="testUser", so value variable will be "testUser" and printed.
  3. Final Answer:

    testUser -> Option A
  4. Quick Check:

    getAttribute("value") = "testUser" [OK]
Quick Trick: getAttribute returns actual attribute value, not element text [OK]
Common Mistakes:
MISTAKES
  • Confusing getAttribute("value") with getText()
  • Expecting attribute name instead of value
  • Assuming null if attribute exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes