柏树如何检查元素是否包含某个字符串
赛普拉斯如何检查元素是否包含某个字符串?
我使用自定义检查元素是否存在代码来检查是否可以找到元素(错误消息) 那么我想检查此元素是否包含某些文本? 还是可以使用查询选择器的Java函数?
cy.validateIfElementExistsInDomAsBoolean('[data-testid=alert-content]').then(bool => { // checks error to file see how it works
if (bool) {
if(cy.contains('[data-testid=alert-content]', "Your basket has been updated. Please refresh the basket to continue.")){
console.log("refresh site")
}else{
console.log("different error")
}
}else{
cy.log("Checked for error no error found")
}
})
Cypress how to check if an element contains a certain string?
I use a custom check if element exists code to check if the element can be found (An error message)
then I want to check if this element contains certain text?
or could I use the java function of query selector?
cy.validateIfElementExistsInDomAsBoolean('[data-testid=alert-content]').then(bool => { // checks error to file see how it works
if (bool) {
if(cy.contains('[data-testid=alert-content]', "Your basket has been updated. Please refresh the basket to continue.")){
console.log("refresh site")
}else{
console.log("different error")
}
}else{
cy.log("Checked for error no error found")
}
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能可以使您的自定义命令返回文本或空字符串
Potentially you can make your custom command return the text or empty string
假设
validateIfelementExistsIndomasBoolean
正确返回布尔值对或false,您可以做这样的事情:如果您必须进行部分字符串检查,则可以替换
为
Assuming
validateIfElementExistsInDomAsBoolean
correctly returns a boolean value true or false, you can do something like this:In case You have to do a partial string check, you can replace
with