Bird
0
0

Which Java Selenium WebDriver command correctly uploads a file located at D:\uploads\image.png using sendKeys()?

easy📝 Syntax Q3 of 15
Selenium Java - Handling Form Elements
Which Java Selenium WebDriver command correctly uploads a file located at D:\uploads\image.png using sendKeys()?
Adriver.findElement(By.id("uploadField")).sendKeys("./image.png");
Bdriver.findElement(By.id("uploadField")).sendKeys("uploads/image.png");
Cdriver.findElement(By.id("uploadField")).sendKeys("D:\\uploads\\image.png");
Ddriver.findElement(By.id("uploadField")).sendKeys("image.png");
Step-by-Step Solution
Solution:
  1. Step 1: Use absolute file path

    Selenium requires the full absolute path to the file for upload.
  2. Step 2: Use double backslashes in Windows paths

    In Java strings, backslashes must be escaped, so use \\ for Windows paths.
  3. Final Answer:

    driver.findElement(By.id("uploadField")).sendKeys("D:\\uploads\\image.png"); -> Option C
  4. Quick Check:

    Absolute path with escaped backslashes [OK]
Quick Trick: Always use absolute path with escaped backslashes on Windows [OK]
Common Mistakes:
MISTAKES
  • Using relative paths instead of absolute
  • Not escaping backslashes in Windows paths
  • Passing only filename without path

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes