Bird
0
0

You have this Selenium code:

medium📝 Debug Q6 of 15
Selenium Java - Handling Form Elements
You have this Selenium code:
driver.findElement(By.name("fileUpload")).sendKeys("document.pdf");

The test throws InvalidArgumentException. What is the most probable cause?
AThe element locator is incorrect and does not find the input element.
BThe file path is relative and not absolute, causing the exception.
CThe file input element is disabled and cannot accept input.
DThe file format PDF is not supported by Selenium sendKeys.
Step-by-Step Solution
Solution:
  1. Step 1: Identify cause of InvalidArgumentException

    This exception often occurs when the file path passed to sendKeys is invalid.
  2. Step 2: Check file path format

    Selenium requires an absolute file path, not a relative one like "document.pdf".
  3. Final Answer:

    The file path is relative and not absolute, causing the exception. -> Option B
  4. Quick Check:

    Use absolute file path for sendKeys [OK]
Quick Trick: sendKeys needs absolute file path, not relative [OK]
Common Mistakes:
  • Using relative file paths instead of absolute
  • Assuming file format affects sendKeys
  • Confusing locator issues with argument exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes