3

I am unable to parse CSRF token from html in Cypress. I am following this link : Logging in using CSRF Token in Cypress

Trying to follow strategy #1 in the above link but I keep getting token as undefined.

This is how my html looks like:

Return html looks like this

This is how my code looks like:

           cy.request({
                url: returnUrlFromLoginAPI,
                followRedirect: false
            })
            .its('body')
            .then((body) => {
                const $html = Cypress.$(body)
                const requestVerificationToken = $html.find("input[name=__RequestVerificationToken]").val()
                console.log(requestVerificationToken)
             })
        })

2 Answers2

0

.find looks for descendants for the current elements set and my meta tag was part of this set and not a descendant. that's why you should use .filter, cause filter looks for current set and its descendants

Chiptus
  • 949
  • 9
  • 25
0

Not sure what the "correct" way is, but I did this:

cy.get('[name=__RequestVerificationToken]').then($rvt => {
   console.log($rvt.val());
}
aleith
  • 434
  • 1
  • 4
  • 10