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

时间:2021-04-14 15:07:25

标签: javascript jquery automation cypress

对 iframe 中的元素执行操作时出现以下错误:

"60000 毫秒后重试超时:预期 '

' 为 '可见' 此元素

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

enter image description here

这是我的元素代码:

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的快照: enter image description here

1 个答案:

答案 0 :(得分:0)

我得到了解决方案。页面中有 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')
})
相关问题