具有数据属性的选择器

Selectors with data attribute

我在为具有 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");

您尝试为 按钮 创建选择器,但您为 div 元素 创建了选择器。看起来你的意思是:

this.nextDesign = Selector("button").withAttribute("data-qa","next-design");

亚历克斯是对的,你没注意到它实际上是一个按钮。

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

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

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