Cypress - "cannot read property 'text' of null" when using cy.log in a .should Callback

Viewed 2158

I'm a Cypress newbie, still trying to figure out the Cypress/JS behavior. The purpose of my script below is to extract the value of a column and store the value as variable. However, I found #Method B throws error which I cannot figure out why this happens. Thanks in advance for any directions or explanations given.

#Method A - works fine

cy.get(`[aria-colindex="4"]`).should(($column) => {
    VPC_UID = $column.text()
}).then( () => {
    cy.log("VPC_UID:"+VPC_UID)
})

#Method B - throws error (see below screenshot)

cy.get(`[aria-colindex="4"]`).should(($column) => {
    VPC_UID = $column.text()
    cy.log("VPC_UID:"+VPC_UID)
})

enter image description here

0 Answers
Related