mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Move uploadFiles onto ElementHandle (#348)
This patch: - removes the `page.uploadFile` method - adds `elementHandle.uploadFile` method. Motivation: `elementHandle.uploadFile` is rarely used, so it doesn't worth it to keep it on page.
This commit is contained in:
committed by
Andrey Lushnikov
parent
ad1b292b6d
commit
5f0afd5547
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const EventEmitter = require('events');
|
||||
const helper = require('./helper');
|
||||
const ElementHandle = require('./ElementHandle');
|
||||
@@ -325,21 +324,6 @@ class Frame {
|
||||
return new WaitTask(this, predicateCode, polling, timeout).promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} selector
|
||||
* @param {!Array<string>} filePaths
|
||||
* @return {!Promise}
|
||||
*/
|
||||
async uploadFile(selector, ...filePaths) {
|
||||
let expression = helper.evaluationString(selector => document.querySelector(selector), selector);
|
||||
const {result} = await this._client.send('Runtime.evaluate', { expression });
|
||||
if (!result)
|
||||
return;
|
||||
const objectId = result.objectId;
|
||||
filePaths = filePaths.map(filePath => path.resolve(filePath));
|
||||
return this._client.send('DOM.setFileInputFiles', { objectId, files: filePaths });
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Promise<string>}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user