6

我使用puppeteer,我有一个dropzone表格。

我想将 chrome headless 中的文件添加到 dropzone 表单中。

我怎样才能做到这一点?

注意:表单包含一些 dropzone 事件中的一些操作(添加文件时)。

4

3 回答 3

1

不确定我是否正确理解了这个问题,但试试这个:

const dropZoneInput = await page.$(inputID);
dropZoneInput.uploadFile(absolutePathToFile);
于 2017-11-20T10:19:25.843 回答
0

我让它和 puppeteer 一起工作:

const fileInput = await page.$(
    ".{yourDropzoneClassName} input[type=file]"
);
await fileInput.uploadFile("path/to/file");
于 2018-10-21T13:09:05.280 回答
0
(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();
})();
于 2021-04-12T17:43:25.933 回答