Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  111] [ 7]  / answers: 1 / hits: 141469  / 6 Years ago, tue, september 25, 2018, 12:00:00

Using Jquery in Cypress.io test, how to get the div 'text' value called 'Wildness' from the below html tag. I have tried below in my Cypress test, but it is throwing undefined in console.



const $divText = Cypress.$('.ibxudA .WildnessText-kRKTej').text()
cy.wrap($divText)
.should(eq, Wildness)




<div class=sc-bMvGRv_onetwo>
<div>
<div class=abLeftSection>
<div class=abNewBtn-fTLJBK>
<button class=ifAKCX ohpWT type=button>New</button>
</div>
<div class=kpLvEV style=>
<div class=cWzXYZ>
<div class=OgGUG>
<div class=jsnnAD>
<svg class=dFvKsA></svg>
</div>
</div>
<div class=ibxudA>First</div>
</div>
<div class=kpLvEV style=>
<div class=bGADLM><div class=OgGUG>
<div class=jsnnAD>
<svg class=dFvKsA></svg>
</div>
</div>
<div class=ibxudA>
<div class=WildnessText-kRKTej title=Wildness>Wildness</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>




More From » jquery

 Answers
32

I might try this:


cy.get(".ibxudA").find('.WildnessText-kRKTej').should('have.text',"Wildness")

or


cy.get(".ibxudA").find('.WildnessText-kRKTej').invoke('text').then((text) => {
expect(text.trim()).equal('Wildness')
});

This might be a similar question: How do you check the equality of the inner text of a element using cypress?


[#53432] Wednesday, September 19, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
reina

Total Points: 241
Total Questions: 82
Total Answers: 94

Location: New Caledonia
Member since Thu, Mar 23, 2023
1 Year ago
reina questions
;