【问题标题】:How can I access the Mac Native Dialog Box如何访问 Mac 本机对话框
【发布时间】:2019-09-17 14:14:44
【问题描述】:

我正在使用的应用程序通过本机 Mac 对话框上传文件。我似乎无法让 Puppeteer 在这个盒子周围移动。我曾尝试使用 process.on(dialog)、page.keyboard.press 和 robotsjs,但这些选项似乎都无法访问此对话框。 process.on 永远不会被触发 page.keyboard 没有做任何事情,我认为是因为该框不在页面上 robotsjs ..我不知道为什么这也不起作用。

有没有人有任何其他建议或可行的解决方案我可以尝试?

page.on('dialog', async (dialog) => {
    await robot.keyTap('tab');
    await robot.typeString(filename);
    await robot.keyTap('tab');
    await robot.keyTap('tab');
    await robot.keyTap('down');
    await robot.keyTap('enter');
});

【问题讨论】:

    标签: javascript node.js puppeteer


    【解决方案1】:

    这是不可能的。无法从 puppeteer 中访问此对话框。

    替代解决方案

    您需要使用elementHandle.uploadFile 将文件放入表单中,而不是单击打开文件对话框的按钮:

    const fileInputField = await page.$('#SELECTOR-OF-FILE-INPUT');
    await fileInputField.uploadFile('PATH/TO/YOUR.FILE');
    

    【讨论】:

    • 很遗憾没有输入框,但谢谢
    【解决方案2】:

    绕过对话框的唯一方法是使用dialog 参数。例如:

    page.on('dialog', dialog => {
        dialog.accept();
        //if it's a prompt
        dialog.accept('Foo');
        //or
        dialog.dismiss();
    });
    

    【讨论】:

      猜你喜欢
      • 2017-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多