在柏树中上传文件

发布于 2025-02-07 09:22:39 字数 581 浏览 1 评论 0原文

我想使用柏树上传.txt文件。有没有办法使柏树选择文件,或者我每次都必须手动选择文件? “窗口弹出”是我希望柏树选择一个文件的地方吗?

感谢您的所有帮助

“按钮的html”

I want to upload a .txt file using Cypress. Is there a way to make Cypress choose the file or do I have to manually select the file every time?
Clicking the 'Choose file' button
window pops up
The 'window pops up' is where I want cypress to select a file, is it possible?

Thanks for all the help

html of the button

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

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

发布评论

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

评论(2

辞别 2025-02-14 09:22:39

您可以使用 selectfile 从cypress中的方法来上传文件。

cy.get('[title="Choose File"]').selectFile('path/to/txt') //Selects the File
cy.get('input[title="Upload"]').click() //Clicks upload button

You can use the selectFile method from cypress to upload the file.

cy.get('[title="Choose File"]').selectFile('path/to/txt') //Selects the File
cy.get('input[title="Upload"]').click() //Clicks upload button
全部不再 2025-02-14 09:22:39

您需要定位input [type =“ file”]才能将文件添加到输入

cy.get('input[type="file"]')
  .selectFile(fileName)
  .trigger('input');               // may also be required               

cy,get('input[type="submit"]).click();

或查找标签并使用sibling()移至输入

cy.contains('label', 'Choose file')
  .sibling('input[type="file"]')
  .selectFile(fileName)
  .trigger('input');               // may also be required               

cy,get('input[type="submit"]).click();

You need to target the input[type="file"] to add the file to the input

cy.get('input[type="file"]')
  .selectFile(fileName)
  .trigger('input');               // may also be required               

cy,get('input[type="submit"]).click();

or by finding the label and using sibling() to move to the input

cy.contains('label', 'Choose file')
  .sibling('input[type="file"]')
  .selectFile(fileName)
  .trigger('input');               // may also be required               

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