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

问题描述 投票:0回答:1

enter image description here

我在下面写了代码

  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')
automation image-uploading e2e-testing testcafe
1个回答
0
投票

似乎您正在尝试在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。该示例显示了如何访问DOM属性并使用断言验证它们(可以“调试” each level of the Selector hierarchy)。

请让我知道是否还有不清楚的地方。

UPDATESelector

© www.soinside.com 2019 - 2024. All rights reserved.