Skip to content

Selectors in cy.get() and cy.contains() cannot find invalid table HTML elements in some situations #25893

Open
@gvaatstra

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");

image

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    E2EIssue related to end-to-end testingTriagedIssue has been routed to backlog. This is not a commitment to have it prioritized by the team.type: unexpected behaviorUser expected result, but got another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions