Cypress 获取子元素包含的元素

dan*_*ord 8 cypress cypress-cucumber-preprocessor

我试图在表中找到 cy.contains() 特定文本的行。

我不能做:

cy.get("tr").contains("specific text")
Run Code Online (Sandbox Code Playgroud)

这将返回包含文本的 span 元素

我不能做

cy.get("tr").contains("specific text").parent()
Run Code Online (Sandbox Code Playgroud)

因为跨度的父级我不是我的

我不能做

cy.get("tr").contains("specific text").parentUnitl("tr")
Run Code Online (Sandbox Code Playgroud)

这不会返回该元素

我也许可以做

cy.get("tr").contains("specific text").parentUnitl("tr").parent()
Run Code Online (Sandbox Code Playgroud)

但我认为对于如此简单的事情来说,这变得非常复杂。

我错过了什么吗?

谢谢

Fod*_*ody 11

你可以做

cy.contains("tr", "specific text")
Run Code Online (Sandbox Code Playgroud)

<tr>即使文本是后代 ,也会返回<span>

cy.get().contains()与异步加载行相比,它还具有更好的重试能力。