Luna
Luna

Reputation: 341

Cannot read property 'click' of undefined - Cypress

I basically want to run the below function but it gives me an error. Please give me a hand if you can. Thank you

 

cy.get('[data-auction-type-text=Regular]').should('be.visible')
            .each(($el,index) => {
                if(index==0){
                    $el.then.click()
                }

Upvotes: 1

Views: 718

Answers (2)

user16461847
user16461847

Reputation:

You can use click() on the $el

cy.get('[data-auction-type-text=Regular]').should('be.visible')
  .each(($el,index) => {
     if (index === 0) {
       $el.click()
     }

or without .each()

cy.get('[data-auction-type-text=Regular]').should('be.visible')
  .eq(0)          // equivalent to if(index==0)
  .click()

Upvotes: 3

Alapan Das
Alapan Das

Reputation: 18650

Instead of $el.then.click() you have to use -

cy.wrap($ele).click()

$ele is a jquery wrapped element. In order to use cypress commands, we have to use wrap.

Upvotes: 0

Related Questions