Skip to main content
Version: Next

Cheat Sheet

Download & Upload#

Download file#

const [ download ] = await Promise.all([
page.waitForEvent('download'),
page.click('button')
]);
const path = await download.path();

Learn more

Upload file#

await page.setInputFiles('input#upload', 'myfile.pdf');

Learn more

Upload multiple files#

await page.setInputFiles('input#upload', ['file1.txt', 'file2.txt']);

Learn more

Upload from memory#

await page.setInputFiles('input#upload', {
name: 'file.txt',
mimeType: 'text/plain',
buffer: Buffer.from('this is test')
});

Learn more

Remove selected files#

await page.setInputFiles('input#upload', []);

Learn more

Handle file picker#

const [fileChooser] = await Promise.all([
page.waitForEvent('filechooser'),
page.click('upload')
]);
await fileChooser.setFiles('myfile.pdf');

Learn more

Manage <iframe>s#

List frames#

const frames = page.frames();

Learn more

Frame by name attribute#

const frame = page.frame('frame-login');

Learn more

Frame by URL#

const frame = page.frame({ url: /.*domain.*/ });

Learn more

Frame by selector#

const frameElementHandle = await page.$('.frame-class');
const frame = await frameElementHandle.contentFrame();

Learn more