Description
Current behavior
When I use cy.contains('start-html', regex'), it does not seem to traverse further in the DOM to match.
Given the simplified HTML
<div data-cy='table_aandachtspunten'>
<table>
<tbody>
<tr data-cy='rowX'>
<a href='abc.com'>"DBU.VR.1"
</tr>
</tbody>
<table>
</div>
It finds the a with both below contain statements (either the full DOM or a specific selector):
cy.contains(^DBU\.VR\.1$).should("be.visible");
cy.contains('[data-cy=tableA] tr a', theRegex).should("be.visible");
but not with a parent element selector (tr which has the needed a element)
cy.contains('[data-cy=tableA] tr', theRegex).should("be.visible");
The relevant code I use:
const theRegex = new RegExp(`^${Cypress._.escapeRegExp("DBU.VR.1")}$`);
cy.contains(theRegex).should("be.visible");
cy.contains('[data-cy=table_aandachtspunten] tr a', theRegex).should("be.visible");
cy.contains('[data-cy=table_aandachtspunten] tr', theRegex).should("be.visible");
I would expect it to find it also when it's not on the exact element
PS: What I also noticed is that the log (both in the runner and the cy.log
command) doesn't include the escape characters, but they are present (when I use a cy.task
with console.log
, I see them).
Desired behavior
Cypress should find the tr
element containing the regex just like you would find it by using cy.contains('parent-element', 'text-to-find')
.
Test code to reproduce
see current behavior
Cypress Version
12.5.1
Node version
16.19.0
Operating System
MacOS
Debug Logs
No response
Other
No response
Activity