我的文件上传中有什么错误? (剧作家)

发布于 2025-02-07 19:13:53 字数 590 浏览 3 评论 0原文

我面对一个问题,即我的文件没有被上传到网站,这是一个代码:

await mainPage.clickElement('locator for the element "Add logo"');
    page.on('filechooser', async (fileChooser) => {
      await fileChooser.setFiles('path to jpg file');
    });

我正在使用“@playwright/test”:“^1.19.2”, 为什么它不起作用,怎么了?
这是一个dom:

https://i.sstatic.net/73q48.png

await mainPage.clickElement('locator for the element "Add logo"');

是一个简单的page.click(),仅在pageObject中使用

I'm facing with an issue that my files are not being uploaded to website, here is a code:

await mainPage.clickElement('locator for the element "Add logo"');
    page.on('filechooser', async (fileChooser) => {
      await fileChooser.setFiles('path to jpg file');
    });

I'm using "@playwright/test": "^1.19.2",
why it is not working, what's wrong?
Here is a DOM:

https://i.sstatic.net/73Q48.png

UPD:

await mainPage.clickElement('locator for the element "Add logo"');

is a simple page.click(), just used from PageObject

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

靖瑶 2025-02-14 19:13:53

您的比赛状况。我建议使用WaitforeVent函数:

const [fileChooser] = await Promise.all([
  page.waitForEvent('filechooser'),
  page.click('locator for the element "Add logo"'),
]);

await fileChooser.setFiles('path to jpg file');

You are having a race condition. I recommend using the waitForEvent function instead:

const [fileChooser] = await Promise.all([
  page.waitForEvent('filechooser'),
  page.click('locator for the element "Add logo"'),
]);

await fileChooser.setFiles('path to jpg file');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文