测试咖啡馆,选择儿童跨度有文字的按钮

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

我正在使用material-ui按钮,将其标签放置在span元素内。我要单击的按钮在其他按钮旁边,唯一使它们唯一的是子span元素中的文本。

“在此处输入图像描述”

我尝试单击这样的按钮:

await t.click(Selector('button').withText('button 2'));

但是它不起作用,因为withText正在将文本作为按钮子项而不是将额外的span元素作为文本的包装器?

无论如何,有关如何单击此按钮的任何建议?

html testing automated-tests e2e-testing testcafe
1个回答
1
投票

您有其他选择。

您可以使用find()

await t.click(Selector('button').find('span').withExactText('button 2'));

或者例如,您使用child()

await t.click(Selector('button').child('span').withExactText('button 2'));

此文档页面及其子章节可能会进一步帮助您:https://devexpress.github.io/testcafe/documentation/reference/test-api/selector/

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