elements / file download
Advanced element
File Download
Practicing browser file download events, intercepting binary streams, inspecting download directories, and asserting file sizes and content.
Available Download Files
#download-links
Clicking any button initiates an actual local browser file download.
- txt file
- #link-download-txt (sample_test_report.txt)
- csv file
- #link-download-csv (test_matrix.csv)
- json file
- #link-download-json (telemetry.json)
- expected
- Triggers a standard browser download event with the filename specified in the download attribute.
Code snippets
Python (Selenium)
import os, time
# Click download
driver.find_element(By.ID, "link-download-txt").click()
time.sleep(1)
# Check downloads folder
download_path = os.path.expanduser("~/Downloads/sample_test_report.txt")
assert os.path.exists(download_path)
with open(download_path) as f:
assert "BugMukti" in f.read()TypeScript (Playwright)
import * as fs from 'fs';
const [download] = await Promise.all([
page.waitForEvent('download'),
page.click('#link-download-txt')
]);
expect(download.suggestedFilename()).toBe('sample_test_report.txt');
const path = await download.path();
expect(fs.existsSync(path!)).toBeTruthy();