Cypress 元素不可见,因为它的有效宽度和高度为 0 x 0 像素

Cypress element is not visible because it has an effective width and height of 0 x 0 pixels

我在对 iframe 中的元素执行操作时遇到以下错误:

“在 60000 毫秒后重试超时:预期‘

’为 'visible' 此元素

不可见,因为它的有效宽度和高度为:0 x 0像素。”

这是我的元素代码:

cy.get('iframeselector',{timeout: 150000})
    .its('0.contentDocument.body').should('not.be.empty')
    .then(cy.wrap).find('p').should('be.visible').clear().type('abc')

我试过使用 {force:true} 甚至通过调用方法更改宽度。但到目前为止对我没有任何用处。任何帮助将不胜感激。

下面是html的截图:

我得到了解决方案。页面中还有 3 个其他 iframe,每个 iframe 都在一个容器内。我打算对第二个 iframe 中的元素执行操作,默认情况下我的代码试图在第一个 iframe 中的元素上工作。

Cyress 没有给出关于找到多个 iframe 的错误。所以它让我失望了 0x0 像素错误。以下对我有用:

  cy.get('parentContainer').within(()=>{
        cy.get('iframeselector',{timeout: 150000})
        .its('0.contentDocument.body').should('not.be.empty')
        .then(cy.wrap).find('p').should('be.visible').clear().type('abc')
})