首页 > 解决方案 > 具有数据属性的选择器

问题描述

我在为具有 data-qa 属性的按钮创建选择器时遇到了麻烦。见html:

<div class="stepsInfo_children__4knGx"><button type="button" class="steps_stepsButton__3Ykpu" data-qa="next-design">

我尝试了这个实现,但没有成功(来自官方文档): this.nextDesign = Selector("div").withAttribute("data-qa","next-design");

标签: testingautomated-testsui-automatione2e-testingtestcafe

解决方案


亚历克斯是对的,你错过了它实际上是一个按钮。

或者您可以避免withAttribute()并创建以下选择器:

this.nextDesign = Selector('[data-qa="next-design"]');

它有点短,这可能使它更具可读性。


推荐阅读