N NextGen Virtual Academy
AD Administrator Learning Manager
SELENIUM WEBDRIVER · PRACTICE LAB

File Upload & Download

Practice file upload, file selection, download links and Selenium file handling techniques.

LAB FILES
OBJECTIVE

What You Will Practice

  • Select a file using a file input.
  • Upload a file using Selenium.
  • Validate the selected file name.
  • Validate file size.
  • Practice download links.
  • Understand download verification.
  • Handle file paths in Selenium.
  • Understand upload and download limitations.
01

File Upload

Select a file from your computer and validate the selected file.

UPLOAD
No file selected.
Selenium Java WebElement upload = driver.findElement(By.id("fileInput"));
upload.sendKeys("C:\\Users\\Student\\Documents\\sample.pdf");
02

File Validation

Validate the selected file name, extension and size.

VALIDATION
File Name
File Type
File Size
Selenium Concept String fileName = upload.getAttribute("value");
03

File Download

Use the download link to practice browser download automation.

DOWNLOAD
↓ Download Practice File
Click the button to download the practice file.
Selenium Concept driver.findElement(By.id("downloadLink")).click();
04

Download Verification

Understand how automation engineers verify that a downloaded file exists.

VERIFY
Expected File

nextgen-selenium-practice.txt

NOT VERIFIED
Java Verification Concept File file = new File(downloadPath);
Assert.assertTrue(file.exists());
05

File Path Practice

Understand absolute and relative file paths used during automation.

FILE PATH
Windows Absolute Path C:\Users\Student\Downloads\file.pdf
Relative Path test-data/sample.pdf
Best Practice String filePath = System.getProperty("user.dir") + "\\test-data\\sample.pdf";
QUICK REFERENCE

Selenium File Handling

Upload
driver.findElement(
    By.id("fileInput")
).sendKeys(
    filePath
);
Click Download
driver.findElement(
    By.id("downloadLink")
).click();
File Exists
File file =
    new File(downloadPath);

Assert.assertTrue(
    file.exists()
);
Project Path
String path =
    System.getProperty(
        "user.dir"
    );