Search code examples
cypress

How cy.click on all buttons starting from 2nd element in Cypress?


How can I click on all the the buttons but starting from the 2nd element? Here is my code:

it('Click menu buttons one by one', function () {

    cy.visit('http://localhost:25000/', { timeout: 300000 })
    cy.wait(10000)
    cy.get('.dijitReset.dijitInline.dijitMenuItemLabel.dijitMenuItem', { timeout: 200000}) .click({multiple: true }) 
    cy.waitSomeTime(10000)

})

Solution

  • Use each():

    cy
      .get('.dijitReset.dijitInline.dijitMenuItemLabel.dijitMenuItem')
      .each(($btn, index) => {
        if (index >= 1) cy.wrap($btn).click();
    });
    

    More examples could be found in the doc here.