search

Home  >  Q&A  >  body text

Loop slideshow excluding clone duplicates in Cypress

I am new to Cypress and am trying to cycle through a slideshow excluding cloned duplicates. I'm using .each() for indexing in cypress but that doesn't work. Below is my code

if (index != 0 && index >= 22) {
    //do something
} else {
    //do something
}

Here is a sample snapshot of my html code:

Can anyone come up with the logic to only loop to the original slide?

P粉197639753P粉197639753277 days ago469

reply all(1)I'll reply

  • P粉677684876

    P粉6776848762024-03-26 12:09:22

    You can use :not() Pseudo selector

    cy.get('div.swiper-slide:not(.swiper-slide-duplicate)')
      .should('have.length', 23)   // to show loop is filtered, remove once confirmed
      .each($swiperSlide => {
        ...
    

    Or if you prefer to inspect inside the loop, use the .not() method

    cy.get('div.swiper-slide')
      .each($swiperSlide => {
        if ($swiperSlide.not(".swiper-slide-duplicate").length) {
    
        } else {
    
        }
      })
    

    reply
    0
  • Cancelreply