Bird
0
0

Consider this code snippet:

medium📝 Predict Output Q5 of 15
Selenium Java - Handling Form Elements
Consider this code snippet:
WebElement upload = driver.findElement(By.cssSelector("input[type='file']"));
upload.sendKeys("/tmp/image.png");
String value = upload.getAttribute("value");
System.out.println(value);

What will be printed?
AThe full file path '/tmp/image.png'
BA runtime exception occurs
CAn empty string or browser-dependent file name
DThe text 'image.png' only
Step-by-Step Solution
Solution:
  1. Step 1: Understand getAttribute("value") on file inputs

    Browsers often mask the file path for security, returning empty or fake file name.
  2. Step 2: Recognize browser security behavior

    Most browsers do not expose full path; output varies but usually not full path.
  3. Final Answer:

    An empty string or browser-dependent file name -> Option C
  4. Quick Check:

    getAttribute("value") on file input = masked or empty [OK]
Quick Trick: File input value attribute hides full path for security [OK]
Common Mistakes:
  • Expecting full file path from getAttribute("value")
  • Assuming getAttribute throws exception here
  • Confusing file name with full path

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes