user12670821
user12670821

Reputation: 83

CYPRESS - Finding and yielding a table row that contains some text

Im trying to get the entire row that contains some text in the child elements. I want to later manipulate it but when I try:

cy.get('.tr').contains('Example Text')

... it always yields/returns the span element. I'd like to point to the div of a "tr" class which contains the text. (I've tried using parent() but then it's 2 elements down so using parent().parent() is not the solution I'm guessing).

e.g. code

<div class="tr">
    <div class="something">
        <span>Example Text</span>
    <div class="something-else">
<div class="tr">
<div class="tr">
<div class="tr">
<div class="tr">
<div class="tr">

Upvotes: 8

Views: 8111

Answers (1)

quirimmo
quirimmo

Reputation: 9988

Try inverting/reversing your logic.

Get the element with the text, and then its tr parent:

cy.contains('Example Text').parent('.tr');

Upvotes: 12

Related Questions