grubyfat
grubyfat

Reputation: 55

How to print text value of the div element in Cypress?

Code

Hey guys, I am new to Cypress and have a hard time finding solution for this problem. The #label element which is a div has a text value and I dont know how to print it to a web console. Appreciate all help

Upvotes: 0

Views: 3517

Answers (1)

Alapan Das
Alapan Das

Reputation: 18634

You can do like this:

cy.get('selector')
  .find('selector')
  .find('selector')
  .find('selector')
  .eq(0)
  .find('selector')
  .eq(1)
  .find('#label')
  .invoke('text')
  .then((text) => {
    cy.log(text) //logs the text
  })

Upvotes: 1

Related Questions