我想将 chrome headless 中的文件添加到 dropzone 表单中。
我怎样才能做到这一点?
注意:表单包含一些 dropzone 事件中的一些操作(添加文件时)。
我想将 chrome headless 中的文件添加到 dropzone 表单中。
我怎样才能做到这一点?
注意:表单包含一些 dropzone 事件中的一些操作(添加文件时)。
不确定我是否正确理解了这个问题,但试试这个:
const dropZoneInput = await page.$(inputID);
dropZoneInput.uploadFile(absolutePathToFile);
我让它和 puppeteer 一起工作:
const fileInput = await page.$(
".{yourDropzoneClassName} input[type=file]"
);
await fileInput.uploadFile("path/to/file");
(async () => {
const browser = await puppeteer.launch({
headless: false,
ignoreDefaultArgs: true
});
const page = await browser.newPage();
await page.goto('https://react-dropzone.js.org/');
await page.waitForSelector('input[type=file]');
const fileInput = await page.$('#rsg-root > div > main > section > section:nth-child(3) > section > section:nth-child(1) > article > div:nth-child(2) > div.rsg--preview-60 > div > section > div > input[type=file]');
await fileInput.uploadFile("./test/playground.js");
///trigger event
await fileInput.evaluate(upload => upload.dispatchEvent(new Event('change', { bubbles: true })));
///
await page.close();
})();