Bird
0
0

You wrote this code to upload a file:

medium📝 Debug Q14 of 15
Selenium Java - Handling Form Elements
You wrote this code to upload a file:
driver.findElement(By.id("fileInput")).sendKeys("docs/report.pdf");

But the file is not uploading. What is the most likely reason?
AThe file path is relative; sendKeys requires the full absolute path.
BsendKeys cannot be used on file input elements.
CThe locator By.id("fileInput") is invalid syntax.
DYou must call click() before sendKeys to upload.
Step-by-Step Solution
Solution:
  1. Step 1: Check file path usage in sendKeys

    sendKeys requires the full absolute file path, not a relative path like "docs/report.pdf".
  2. Step 2: Verify other options

    sendKeys works on file inputs; locator syntax is correct; click() before sendKeys is not needed.
  3. Final Answer:

    The file path is relative; sendKeys requires the full absolute path. -> Option A
  4. Quick Check:

    Use absolute path in sendKeys [OK]
Quick Trick: Always provide absolute file path to sendKeys [OK]
Common Mistakes:
MISTAKES
  • Using relative file paths
  • Thinking click() is required before sendKeys
  • Misunderstanding locator syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes