testcafe,select 子跨度有文本的按钮

test cafe, select button where child span has text

我正在使用 material-ui 按钮,这些按钮将其标签放在 span 元素中。我尝试单击的按钮紧挨着其他按钮,唯一使它们独一无二的是子 span 元素中的文本。

我试过这样点击按钮:

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

但它不起作用,我假设它是因为 withText 正在寻找文本作为按钮的子项,而不是作为文本包装器的附加跨度元素?

无论如何,关于如何单击此按钮有什​​么建议吗?

您有更多选择。

您可以使用 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/