在 TestCafe 中上传文件时无法找到元素

Unable to find element when uploading file in TestCafe

在此处输入图片描述

下面是我写的代码

let browseButton = await Selector('input').withAttribute('id', 'card_image_1583116662160_11.707407693474106'); await t .click(Selector('.fa.fa-image')) // upload img .setFilesToUpload(browseButton,'../../artifacts/uploads/boba.jpg')

但结果是

1) The specified selector does not match any element in the DOM tree.

         | Selector('input')
       > |   .withAttribute('id', 'card_image_1583116662160_11.707407693474106')

您似乎正试图在 Selector 中使用动态 ID。在这种情况下,您应该根据 CSS 类 或其他非动态属性创建 Selector。请参阅此文档部分:https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/selectors/.

以下示例也可能有用:https://github.com/DevExpress/testcafe-examples/blob/master/examples/element-properties/check-element-markup.js. The example shows how to access DOM properties and verify them with assertions (you can "debug" each level of the Selector hierarchy).

如有任何不明之处,请告诉我。

更新Select Elements With Dynamic IDs

更新 2RegExp example - Selector('input').withAttribute('id', /card_image_\w+/)