我是 Cypress 的新手,正在尝试循环滑动幻灯片,排除克隆的重复项。我在 cypress 中使用 .each() 的索引,但这不起作用。下面是我的代码
if (index != 0 && index >= 22) {
//do something
} else {
//do something
}
下面是我的 html 代码的示例快照:
任何人都可以提出仅循环到原始幻灯片的逻辑吗?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您可以使用
:not()伪选择器cy.get('div.swiper-slide:not(.swiper-slide-duplicate)') .should('have.length', 23) // to show loop is filtered, remove once confirmed .each($swiperSlide => { ...或者如果您更喜欢检查循环内部,请使用
.not()方法cy.get('div.swiper-slide') .each($swiperSlide => { if ($swiperSlide.not(".swiper-slide-duplicate").length) { } else { } })