DEV Community

Cover image for How to get DOM element text value in cypress
Amir Sohel
Amir Sohel

Posted on

How to get DOM element text value in cypress

Hi Folk 🙋🏼

Now days develoepr has to write test cases for their component code and for test their own functionality.

there are many tools in market like
Chai Moka Jasmine Karma Jest

but Cypress is single tool which is running on top of these above tools. becuase internally cypress use these mentioned tools including Jquery.

Cypress allow you to test your application e2e in browser with very smooth flow.

but sometime while working with cypress we need to get a element and match it's value with another element dynamically so how we can achive that

here I am going to show you how we can take innerText of any DOM element in cypress

cy.get(['YOUR_DOM_ELEMENT']).then(elm => {
  cy.get(['YOUR_DOM_ELEMENT']).should('has.text', elm[0].innerText)
});
Enter fullscreen mode Exit fullscreen mode

Top comments (0)