【发布时间】:2020-04-18 04:33:05
【问题描述】:
到目前为止,我已经尝试了两件事。
const iconupload = await page.$x(xpath); //Triple-checked that this x path is correct
iconupload[0].uploadFile(picture); //Triple-checked that this picture path is correct
和
await page.evaluate((picturepath) => {
document.querySelector('input[type=file]').value = picturepath
}, picturepath);
对于第一种方法,我得到一个
TypeError: Cannot read property 'uploadFile' of undefined
对于第二种方法,我得到一个
Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.
有没有办法将图像上传到这个输入?
【问题讨论】:
-
您能否详细说明您要做什么?
-
请提供更多详细信息,例如您尝试使用 xPath 访问的 DOM 或 HTML 以及您尝试上传的文件输入元素。
-
@Trobol 上传图片到我的谷歌账户页面
-
@EdiImanto ...如果您愿意,我可以提供更多 HTML 代码
标签: javascript node.js puppeteer