Created
October 24, 2023 02:55
-
-
Save CodeLeom/bd4c7c17a0749044f7a1a9b606c3e5ae to your computer and use it in GitHub Desktop.
Automating a File Upload with Puppeteer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import puppeteer from "puppeteer"; | |
// function to handle timeout | |
function delay(time) { | |
return new Promise(resolve => setTimeout(resolve, time)); | |
} | |
const browser = await puppeteer.launch({ | |
headless: false | |
}); | |
const page = await browser.newPage(); | |
await page.goto('https://easyupload.io/'); | |
await page.waitForSelector('input[type=file]'); | |
const inputUploadHandle = await page.$('input[type=file]'); | |
await inputUploadHandle.uploadFile('./testdoc.pdf'); | |
// There may be a submit button to finalize the resume submission. | |
await page.click('#upload'); | |
// Introduce a delay if necessary | |
await delay(20000); | |
// Wait for a success message or acknowledgment. | |
await page.waitForSelector('.upload-success'); | |
await browser.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment