赛普拉斯-如何通过文本内容查找? [英] Cypress - how to find by text content?
本文介绍了赛普拉斯-如何通过文本内容查找?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在赛普拉斯中,我想根据其文本内容从一组按钮中选择一个按钮.我该怎么做?这是我的方法:
In Cypress, I want to select a button from a group of buttons based on its text-content. How can I do it? Here is my approach:
export const getCustomerButton = () => getNavigationSidenav()
.find('mat-expansion-panel-header')
.each(($el, index, $list) => {
const text = $el.find('.mat-content > mat-panel-title').text();
if (text === 'Customer') {
return $el;
}
return null;
});
我现在遇到的问题是我必须从元素数组中过滤出空值.有没有那么简单的方法?
The problem I have now is that I have to filter out the nulls from the element array. Is there a less complicated way?
推荐答案
这将产生带有 YOUR_BUTTON_CLASS
的DOM元素,其中包含文本"Customer".那是您要找的东西吗?
This will yield the DOM element with YOUR_BUTTON_CLASS
which contains text 'Customer'. Is that what you're looking for?
cy.get('YOUR_BUTTON_CLASS').contains('Customer');
此处是 .contains
的文档.> cypress命令.
Here the documentation for .contains
cypress command.
这篇关于赛普拉斯-如何通过文本内容查找?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文