【问题标题】:How to get length by children collactions with Cypress?如何通过与 Cypress 的子级排序获得长度?
【发布时间】:2020-11-12 13:36:23
【问题描述】:

我将 Cypress.io 与 ReactJs 一起使用

我有html结构

<ul class="wrapper">
  <li class="class-1">1</li>
  <li class="class-2">2</li>
  <li class="class-3">3</li>
  <li class="class-4">4</li>
  <li class="class-5">5</li>
</ul>

我怎样才能得到 li elems 的长度? 像这样document.querySelector(.wrapper &gt; li).length

cy.get('.wrapp > li').length 不起作用

【问题讨论】:

    标签: reactjs cypress


    【解决方案1】:

    就像Cypress docs中所说的那样

    cy.get('.wrapper li')       // this yields us a jquery object
      .its('length')
      .then(length =>{
        //code that uses the length
      })
    
    

    【讨论】:

      【解决方案2】:

      你可以使用类似的东西:

      cy.get('.wrapper').find('li').its('length').then((len) => {
          //Do stuff with length
          expect(len).to.equal(5)
      })
      

      【讨论】:

        猜你喜欢
        • 2011-03-06
        • 1970-01-01
        • 1970-01-01
        • 2023-03-28
        • 2015-11-11
        • 1970-01-01
        • 1970-01-01
        • 2015-03-12
        • 1970-01-01
        相关资源
        最近更新 更多