Cypress-反转每个

问题描述 投票:0回答:1

我需要反向从数组中取出元素。我必须从最后一个开始。与jQuery“反向”相比,在Cypress中找不到任何其他解决方案可使用,但是我在使用时遇到问题。

不能同时使用:

 cy.get('.btn-remove.action.delete').reverse().each(($el, index, $list) =>  {
                        cy.get($el).click({force:true})
                       cy.wait(1000)
                })

来自赛普拉斯的答复-TypeError:cy.get(...)。reverse不是函数

cy.get('.btn-remove.action.delete').invoke('reverse').each(($el, index, $list) =>  {
                        cy.get($el).click({force:true})
                        cy.wait(1000)
                })

来自Cypress的答案-CypressError:超时重试:cy.invoke()错误,因为您的主题上不存在属性'reverse'。

或者也许有其他方法与reverse()不同?

jquery each cypress
1个回答
0
投票

有关尝试使用for循环并使用eq()从头开始迭代的问题,

cy.get('.btn-remove.action.delete').its('length').then((numberOfItems) => {
  for (var i = numberOfItems-1; i>=0; i--) {
    cy.get('.btn-remove.action.delete').eq(i).click({force:true})
  }
})

也许这不是最干净的方法,但是应该可以。

不确定您的代码中的cy.wait(1000)是什么,但是这里不需要。 (Actually, you should avoid using cy.wait() as much as possible)

让我知道是否有任何疑问。

© www.soinside.com 2019 - 2024. All rights reserved.