Browser

File Downloads, Uploads, and Export

LeftClickAndDownload clicks an element and waits for the browser to download the file, saving it to the given GPALFile path. RightClickAndDownload right-clicks and uses Save As. LeftClickAndUpload clicks a file input and hands it the file. PrintToPDF writes a PDF of an element or of the whole page, and has its own page. SaveTo(GPALFile) writes the data collected by the current selector, and the file extension decides the format, so a .csv, a .xlsx, a .json or a .txt all come from the same call. AppendTo(GPALFile) adds to an existing file rather than overwriting it. SaveTo(ref string) is the other direction entirely: it hands back response bodies from Fetch rather than writing anything.

NOTE

Configure download behavior with WithDownloadLocation (directory), WithDownloadTimeoutInSec (wait time), and WithOverwriteExistingFile (true to overwrite, false to auto-rename). These are typically set during browser setup before the first navigation.

WARNING

LeftClickAndDownload, LeftClickAndUpload, RightClickAndDownload, PrintToPDF, and the SaveTo* export methods only have a GPALFile overload - there is no separate string overload to compete with it. Because GPALFile has an implicit conversion from string, a plain path string can be passed directly, e.g. .LeftClickAndDownload("C:\Downloads\report.pdf"). GPAL.FileFor(...) is equivalent and mainly useful when you want to build and reuse a GPALFile reference across multiple calls.

Examples

GPAL Fluent: High-level fluent C# API

//LeftClickAndDownload waits for the file to appear in the download directory before returning. Use WithDownloadTimeoutInSec to extend the wait for large files.

// Download a file by clicking a link

GPAL.Browser

.GoTo("https://example.com/reports")

.WithSelector(".download-link")

.LeftClickAndDownload("C:\Downloads\report.pdf");


// Upload a file

browser

.WithSelector("#file-input")

.LeftClickAndUpload("C:\data\import.csv");


// Export scraped table data to CSV

var scraped = GPAL.Grid.ToGPALObject();


browser

.GoTo("https://example.com/data")

.WithSelector(".row")

.WithAllThatMatch(1000)

.GetGrid(ref scraped)

.SaveTo((GPALFile)"scraped.csv");

💬 Ask GPAL