References

File Upload: Attaching Files Without a Dialog

Attaching Files Without a Dialog

LeftClickAndUpload attaches files to a file input element without opening the operating system file picker. Build a GPALFile by chaining one or more WithFileName calls, then pass it to LeftClickAndUpload. GPAL reads each file from disk and delivers it to the browser directly, triggering the same change and input events a real selection would fire.

GPALFile files = GPAL.File

.WithFileName(@"C: eportsinvoice.pdf")

.ToGPALObject();


browser

.WithSelector("input[type=file]")

.WaitFor(3_000)

.LeftClickAndUpload(files);

NOTE

Chain as many WithFileName calls as needed. GPAL sends each file in sequence and the input accumulates them, so the element ends up holding all of them when the call returns.

How Each Engine Delivers the File

GPAL picks the right delivery path automatically based on the configured automation engine. Selenium uses SendKeys on the file input, which the WebDriver protocol handles natively. Puppeteer uses page.setInputFiles via the Chrome DevTools Protocol. OttoMagic has no native file path -- instead, GPALRestAPI reads the file, base64-encodes it, and sends the bytes through the native messaging pipe to the extension, which reconstructs a File object using the DataTransfer API and assigns it to the input directly. The workflow code is identical regardless of engine.

// Same code works across all engines

GPALFile batch = GPAL.File

.WithFileName(@"C:data eport1.csv")

.WithFileName(@"C:data eport2.csv")

.ToGPALObject();


browser

.WithSelector("#upload-input")

.LeftClickAndUpload(batch);

NOTE

None of these paths open the operating system file picker. The file lands in the input's files property directly, so the workflow never blocks waiting for user interaction.

Targeting Hidden File Inputs

Many sites style file inputs with opacity zero or position them off-screen and layer a visible button on top. The visible button is for users -- the real input is the hidden element underneath. Target the hidden input[type=file] directly with WithSelector. GPAL can assign files to it regardless of visibility because the assignment goes to the DOM property, not through a simulated click on what the user sees. If the input only appears after some prior interaction, use WaitFor before LeftClickAndUpload to let the element settle.

// Target the hidden input directly,

// not the visible styled button

browser

.WithSelector(

"#dropzone > input[type=file]")

.WaitFor(5_000)

.LeftClickAndUpload(files);

NOTE

With OttoMagic, the file travels through the native messaging pipe as base64, adding roughly 33 percent overhead. Very large files can delay other commands queued behind the upload call. Selenium and Puppeteer pass a file path instead, so size has no pipe impact.

💬 Ask GPAL