【问题标题】:Not getting text content using cypress没有使用 cypress 获取文本内容
【发布时间】:2019-07-12 09:09:43
【问题描述】:

使用 cypress 我试图从表中的所有标题元素中获取文本但显示错误

我尝试过 text/inner text/textcontent 等同样的问题。

CypressError:重试超时:cy.its() 出错,因为属性:'outerText' 在您的主题中不存在。

 cy.wrap($table).find('th').each(($header)=>{
 cy.wrap($header).its('outerText').then((Text)=>{
 cy.log(Text);
})

我希望在这种情况下使用文本性别

这是我的 cy.wrap 产生的对象

【问题讨论】:

    标签: text cypress


    【解决方案1】:

    我通过使用 invoke 和 .then 找到了解决方案

    现在我得到了我想要的文本 cy.wrap($header).invoke('text').then(($elementvalue)=>{ cy.log($elementvalue);

    【讨论】:

      【解决方案2】:

      由于 Cypress 正在生成 jquery 实例,因此您需要先将其解包以访问本机 dom 元素属性:

      cy.get('#my-el').should($el => {
        expect($el[0].outerText).to.contain('Gender')
      })
      

      【讨论】:

        【解决方案3】:

        试试这个

         cy.window().then((win) => {
              console.log(
                win.document.querySelector(".minimal_filter_tags").textContent
              );
            });
        

        【讨论】:

          猜你喜欢
          • 2020-01-12
          • 1970-01-01
          • 2020-07-05
          • 2011-04-15
          • 2022-06-16
          • 1970-01-01
          • 2021-12-11
          • 2019-03-27
          • 2023-03-07
          相关资源
          最近更新 更多